如何解决从Kubernetes中的其他命名空间调用Rest API
我在Kubernetes中部署了REST API应用程序YAML,并尝试从另一个名称空间访问该API。但它显示错误。如何从其他名称空间访问其余API。以下是我的部署YAML
apiVersion: apps/v1
kind: Deployment
metadata:
name: configuration
labels:
app: configuration
namespace: restapi
spec:
replicas: 1
selector:
matchLabels:
app: configuration
template:
metadata:
labels:
app: configuration
spec:
containers:
- name: configuration
image: global.azurecr.io/config:1
env:
- name: AzureFunctionsJobHost__functions__0
value: configuration
envFrom:
- secretRef:
name: configuration
imagePullSecrets:
- name: pull
来自其他命名空间的API调用的URL是 “ http://configuration.restapi:80 / api / configuration” 我在网址中尝试了 .restapi ,但无法正常工作。 我可以在同一名称空间中调用rest API。
解决方法
您始终可以进行简单的测试,以检查是否可以从其他名称空间访问。
让我们说您没有服务。
然后您可以使用如下所示的ip直接访问广告连播。
kubectl run dnstest --image=busybox:1.28 --restart=Never --rm -ti -- nslookup 10-36-0-2.default.pod
Server: 10.96.0.10
Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local
Name: 10-36-0-2.default.pod
Address 1: 10.36.0.2
pod "dnstest" deleted
如果您像下面那样公开服务
kubectl expose deployment configuration --port 80 -n restapi
然后测试结果如下。
kubectl run dnstest --image=busybox:1.28 --restart=Never --rm -ti -- nslookup configuration.restapi
Server: 10.96.0.10
Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local
Name: configuration.restapi
Address 1: 10.105.110.174 configuration.restapi.svc.cluster.local
pod "dnstest" deleted
您可以在标准kubernetes环境中使用configuration.restapi或configuration.restapi.svc或configuration.restapi.svc.cluster.local。
,假设configuration.restapi是您要访问的服务的名称,并且是您要在该命名空间中使用的名称,则可以使用“ configuration.restapi.othernamespace.svc.cluster.local”。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。