How do you configure a TCP liveness probe with container-to-container networking in a k8s pod?
Here is an example deployment using TCP liveness probe, TCP readiness probe and networking between containers in a pod with the server containers port exposed:
test.yml
apiVersion: extensions/v1beta1kind: Deploymentmetadata: name: testspec: 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'
Creating and verifying the deployment:
> kubectl create -f test.yml> kubectl get pod -l app=testNAME READY STATUS RESTARTS AGEtest-620943134-fzm05 2/2 Running 0 1m> kubectl log test-620943134-fzm05 clientpongpongpong[…]