readinessProbe use DNS instead of IP Address for Host

4/28/2020

I currently configure my Nginx Pod readinessProbe to monitor Redis port 6379, and I configure my redis-pod behind the redis-service (ClusterIP).

So my idea is to monitor Redis port though redis-service using DNS instead of IP address.

When I use readinessProbe.host: redis-service.default.svc.cluster.local the Nginx-pod is not running. When I describe the Nginx-pod $ kubectl describe pods nginx, I found below error in Events section:

Readiness probe failed: dial tcp: lookup redis-service.default.svc.cluster.local: no such host

It only works if I use ClusterIP instead of DNS.

Please help me figure out how to use DNS instead of ClusterIP.

My Pod file:

apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: nginx
  name: nginx
spec:
  containers:
  - image: nginx
    name: nginx
    livenessProbe:
      httpGet:
        path: /
        port: 80
    readinessProbe:
      tcpSocket:
        host: redis-service.default.svc.cluster.local
        port: 6379
    resources: {}
  dnsPolicy: ClusterFirst
  restartPolicy: Always

Thanks.

-- hazard74
kubernetes
nginx
redis

1 Answer

4/30/2020

I figured out how to do it.

Instead of using tcpSocket, just use exec. Exec your tcpCheck script inside the container to check the service:port availability.

Use your init-container to share the script with the main container.

Thanks.

-- hazard74
Source: StackOverflow