1

we have a need for an external clients to connect to the POD via static hostname running on Kubernetes containers/sessions. The issue is that whenever we restart a session we get a new hostname generated for that container. Is there a way we can get a fixed hostname for the pods, such that it doesn't change every time we restart ??

$ kubectl get pods
NAME                                                              READY   STATUS             RESTARTS   AGE
anaconda-app-0072b5a97aad4bc5ba708a405609ad2e-74757d95fd-4cfms    2/2     Running            521        18d
anaconda-app-048b92d480d34da3a6602eace5f4c1c4-84d5669674-drx2c    1/2     CrashLoopBackOff   5086       77d
anaconda-app-0a529b10874e4c79a361050897bf3a00-64fdf8967f-ctc9z    2/2     Running            521        18d
anaconda-app-128b6866e59a408d937768835c04666c-5b774b8977-rhbp7    1/2     CrashLoopBackOff   5087       18d

If we can get a static name for the pods whenever the session is restarted that would be awesome, such that we can give one single static IP/hostname to the clienst?

stack user
  • 300
  • 2
  • 9
  • 3
    You should probably have a Service in front of the Pods, and that Service's name will be stable. – David Maze Feb 18 '21 at 03:00
  • 2
    You are asking two different questions in one, and they have wildly different answers: (a) "can get a fixed hostname for the pods", trivially by setting [`spec: hostname:`](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.20/#podspec-v1-core) (b) "connect to the POD via static hostname" is more what David said, and it is a ton of work to have the outside world connect reliably to _one Pod_ since that's not how k8s thinks about the world – mdaniel Feb 18 '21 at 05:48
  • @DavidMaze when i run $ kubectl get serviceaccounts it does show that I do have serviceaccount, "anaconda-enterprise" yet my PODS always generate something like this "anaconda-app-0072b5a97aad4bc5ba708a405609ad2e-74757d95fd-4cfms " and are different every time session restarts – stack user Feb 18 '21 at 12:50
  • Service, not ServiceAccount. And yes, every replica of your Deployment will have a different pod name, and it will change every time you change any part of the Deployment. – David Maze Feb 18 '21 at 12:57
  • Please read the docs about [Service](https://kubernetes.io/docs/concepts/services-networking/service/). There is everything you need to know. In case you decide that this is not for you (I mean the service, not reading) checkout [StatefulSet](https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/). If then you still have no idea what to do, comeback and with prevoiusly acquired knowledge ask more detailed question. – Matt Feb 19 '21 at 11:30

1 Answers1

0

consider running a statefulset with one replica. host name remains same for statefulset

P Ekambaram
  • 15,499
  • 7
  • 34
  • 59