我注意到pod中的容器可以使用localhost相互通信,就像广告所说的那样。例如,一个容器在localhost:9999上启动一个服务器套接字,第二个容器可以连接到该地址。如果我公开服务器容器的端口,则此操作将失败。同样,如果我在该端口上创建TCP活动探测,它也会失败。活跃性探测器似乎使用pod IP地址,除非暴露出来,否则无法连接到localhost:9999。如果两个容器都使用pod IP,即$HOSTNAME:9999,并且端口公开,则一切正常。有没有一个例子,每个容器都使用localhost,TCP探测也有效?
发布于 2017-09-21 17:28:43
下面是一个示例部署,使用TCP活动探测、TCP就绪探测以及暴露服务器容器端口的pod中的容器之间的网络:
test.yml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: test
spec:
template:
metadata:
labels:
app: test
spec:
containers:
- name: server
image: alpine
command:
- '/bin/sh'
- '-c'
- 'nc -p 8080 -kle echo pong'
livenessProbe:
tcpSocket:
port: 8080
readinessProbe:
tcpSocket:
port: 8080
ports:
- containerPort: 8080
- name: client
image: alpine
command:
- '/bin/sh'
- '-c'
- 'while true; do echo -e | nc localhost 8080; sleep 1; done'创建和验证展开:
> kubectl create -f test.yml
> kubectl get pod -l app=test
NAME READY STATUS RESTARTS AGE
test-620943134-fzm05 2/2 Running 0 1m
> kubectl log test-620943134-fzm05 client
pong
pong
pong
[…]https://stackoverflow.com/questions/46328039
复制相似问题