How to create Kubernetes endpoints if it depends on another service endpoint

5/20/2019

I am creating a pod in kubernetes that has two containers. One container tries to find the endpoint of a running service. If it does not find it, it will exit, causing it to restart, cause the pod #1 container to not configure an endpoint ip.

Pod #2 does the same thing but it is looking for the endpoint for pod #1 that will not configure until pod #1 finds endpoint for pod #2.

How do I get around this, where both endpoints for the pods are created and they connect to each other.

-- adrian humphrey
kubernetes
kubernetes-service

1 Answer

5/21/2019

Maybe you can handle this through publishing NotReady address, like this example:

apiVersion: v1
kind: Service
metadata:
  annotations:
    service.alpha.kubernetes.io/tolerate-unready-endpoints: "true"
  name: harbor-1-redis-announce-0
  namespace: registry
spec:
  ports:
  - name: server
    port: 6379
    protocol: TCP
    targetPort: redis
  publishNotReadyAddresses: true
  selector:
    release: harbor-1-redis

Through Annotations and setting publishNotReadyAddresses to true, you can get the endpoints before the Pods get ready.

-- Kun Li
Source: StackOverflow