无法在外部 ip Kubernetes 访问服务
Cannot access service at external ip Kubernetes
我有一个问题,尽管我有外部 IP.I 满足超时请求,但我无法使用 curl 访问服务。这是我的服务
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
crawler-manager-1 NodePort 10.103.18.210 192.168.0.10 3001:30029/TCP 2h
redis NodePort 10.100.67.138 192.168.0.11 6379:30877/TCP 5h
这是我的 yaml 服务文件:
apiVersion: v1
kind: Service
metadata:
annotations:
kompose.cmd: C:\ProgramData\chocolatey\lib\kubernetes-kompose\tools\kompose.exe
convert -f docker-compose.yml
kompose.version: 1.17.0 (a74acad)
creationTimestamp: null
labels:
io.kompose.service: crawler-manager-1
name: crawler-manager-1
namespace: cbpo-example
spec:
type: NodePort
externalIPs:
- 192.168.0.10
ports:
- name: "3001"
port: 3001
targetPort: 3001
selector:
io.kompose.service: crawler-manager-1
run: redis
status:
loadBalancer: {}
这里是我的部署yml文件
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:
kompose.cmd: C:\ProgramData\chocolatey\lib\kubernetes-kompose\tools\kompose.exe
convert -f docker-compose.yml
kompose.version: 1.17.0 (a74acad)
creationTimestamp: null
labels:
io.kompose.service: crawler-manager-1
name: crawler-manager-1
namespace: cbpo-example
spec:
replicas: 1
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
io.kompose.service: crawler-manager-1
spec:
hostNetwork: true
containers:
- args:
- npm
- start
env:
- name: DB_HOST
value: mysql
- name: DB_NAME
- name: DB_PASSWORD
- name: DB_USER
- name: REDIS_URL
value: redis://cbpo-redis
image: localhost:5000/manager
name: crawler-manager-1
ports:
- containerPort: 3001
resources: {}
restartPolicy: Always
status: {}
有人在使用 kubernetes 时遇到像我这样的问题吗?我需要访问以检查我的命名空间中的 2 个服务是否可以相互连接,非常感谢。
您可以使用服务的 DNS 名称进行通信,而不是通过 IP 地址进行通信。
“Normal” (not headless) Services are assigned a DNS A record for a
name of the form my-svc.my-namespace.svc.cluster.local. This resolves
to the cluster IP of the Service.
“Headless” (without a cluster IP)
Services are also assigned a DNS A record for a name of the form
my-svc.my-namespace.svc.cluster.local. Unlike normal Services, this
resolves to the set of IPs of the pods selected by the Service.
Clients are expected to consume the set or else use standard
round-robin selection from the set.
更多信息,请查看Kubernetes DNS for Services
我有一个问题,尽管我有外部 IP.I 满足超时请求,但我无法使用 curl 访问服务。这是我的服务
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
crawler-manager-1 NodePort 10.103.18.210 192.168.0.10 3001:30029/TCP 2h
redis NodePort 10.100.67.138 192.168.0.11 6379:30877/TCP 5h
这是我的 yaml 服务文件:
apiVersion: v1
kind: Service
metadata:
annotations:
kompose.cmd: C:\ProgramData\chocolatey\lib\kubernetes-kompose\tools\kompose.exe
convert -f docker-compose.yml
kompose.version: 1.17.0 (a74acad)
creationTimestamp: null
labels:
io.kompose.service: crawler-manager-1
name: crawler-manager-1
namespace: cbpo-example
spec:
type: NodePort
externalIPs:
- 192.168.0.10
ports:
- name: "3001"
port: 3001
targetPort: 3001
selector:
io.kompose.service: crawler-manager-1
run: redis
status:
loadBalancer: {}
这里是我的部署yml文件
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:
kompose.cmd: C:\ProgramData\chocolatey\lib\kubernetes-kompose\tools\kompose.exe
convert -f docker-compose.yml
kompose.version: 1.17.0 (a74acad)
creationTimestamp: null
labels:
io.kompose.service: crawler-manager-1
name: crawler-manager-1
namespace: cbpo-example
spec:
replicas: 1
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
io.kompose.service: crawler-manager-1
spec:
hostNetwork: true
containers:
- args:
- npm
- start
env:
- name: DB_HOST
value: mysql
- name: DB_NAME
- name: DB_PASSWORD
- name: DB_USER
- name: REDIS_URL
value: redis://cbpo-redis
image: localhost:5000/manager
name: crawler-manager-1
ports:
- containerPort: 3001
resources: {}
restartPolicy: Always
status: {}
有人在使用 kubernetes 时遇到像我这样的问题吗?我需要访问以检查我的命名空间中的 2 个服务是否可以相互连接,非常感谢。
您可以使用服务的 DNS 名称进行通信,而不是通过 IP 地址进行通信。
“Normal” (not headless) Services are assigned a DNS A record for a name of the form my-svc.my-namespace.svc.cluster.local. This resolves to the cluster IP of the Service.
“Headless” (without a cluster IP) Services are also assigned a DNS A record for a name of the form my-svc.my-namespace.svc.cluster.local. Unlike normal Services, this resolves to the set of IPs of the pods selected by the Service. Clients are expected to consume the set or else use standard round-robin selection from the set.
更多信息,请查看Kubernetes DNS for Services