0

Need to set the ip and/or any metadata of the deployment to be available as env vars to each pod under the same deployment...

ex: having a 3 replica deploment. need to set env var for other IP address for each of the two other pods. need to set the host name for each other two pods. as of having

HOSTNAME=deplymentNAME-d74cf6f77-q57jx
deplymentNAME_PORT=tcp://10.152.183.27:13000

need to add:

HOSTNAME2=deplymentNAME-d74cf6f77-y67kl
HOSTNAME3=deplymentNAME-d74cf6f77-i90ro
deplymentNAME_PORT2=tcp://10.152.183.45:13000
deplymentNAME_PORT3=tcp://10.152.16.28:13000

those should be available on the three pods relatively. as of now each pod have only its own data, we need to spread others data to the other replicas in the same deployment.

  • Why are you using pods IP's and not service IPs for the pods? – jaxxstorm Jul 08 '18 at 23:38
  • Sounds like you should try to leverage an external entity / witness to manage this data -- i.e., have you considered a service discovery solution such as Zookeeper, Consul, Etcd, etc? – the_marcelo_r Jul 09 '18 at 01:23
  • @jaxxstorm i need this for application that need to do inter-connection multiplexing. – Michael Eino Jul 09 '18 at 09:13
  • @theMarceloR not possible to get at least a resolvable DNS name for the neighboring instances ?? this answer is really near https://stackoverflow.com/a/34418819/7791096 but for the pod itself,, if we can do that by using lables/selectors, it is gonna be awesome – Michael Eino Jul 09 '18 at 09:16
  • @MichaelEino, everything is possible. Specially if you are willing to code it, e.g., https://godoc.org/golang.org/x/build/kubernetes#Endpoint. You could create something similar to the `Downward API` (https://kubernetes.io/docs/tasks/inject-data-application/environment-variable-expose-pod-information/#the-downward-api) and retrieve the data you want and inject into your deployment metadata as environment variables but you will need an admission controller to tweak your Deployment manifests on the fly: https://kubernetes.io/docs/reference/access-authn-authz/admission-controllers/. – the_marcelo_r Jul 09 '18 at 10:13
  • @theMarceloR on the example you share [link](https://kubernetes.io/docs/tasks/inject-data-application/environment-variable-expose-pod-information/#the-downward-api) `name: MY_POD_IP valueFrom: fieldRef: fieldPath: status.podIP` is that need admission controller, its not stated there.. or is it pre-configured ? and can I select a **fieldPath** for another pod? – Michael Eino Jul 10 '18 at 07:43
  • The Downward API can be used without the addition of any k8s customization. If you want to use `status.podIP`, you can just declared it. -- However, if you want to change the YAML on the fly as soon as the deployment manifest is sent to the Control Plane, then you could use an admission controller to mutate the k8s object (and its metadata descriptor -- the yaml). More context: https://medium.com/ibm-cloud/diving-into-kubernetes-mutatingadmissionwebhook-6ef3c5695f74 – the_marcelo_r Jul 10 '18 at 13:04
  • Hmm.. Have you tried init containers? – d0bry Jul 10 '18 at 19:47
  • @d0bry interesting ! i can create init container to get the IPs/DNSs from the API like: `https://kubernetesHost/api/v1/pods/?labelSelector=k8s-app=%20myapp01` then inject them as envvar ... not sure if that gonna work, does the init container start after the replica creation ? – Michael Eino Jul 16 '18 at 07:30
  • May you try to [communicate containers in the same pod](https://kubernetes.io/docs/tasks/access-application-cluster/communicate-containers-same-pod-shared-volume/) and use [init containers](https://kubernetes.io/docs/concepts/workloads/pods/init-containers/)? Drop a line if it helped a bit. – d0bry Jul 16 '18 at 11:01
  • @d0bry no I need inter-pod container communication... the application is a cluster aware.. and need to know where other instances running. I need all pods spread over the cluster to be defined on each pod, so the app would be aware of what is going on behind :) ... the init container should work... and the solution mentioned by theMarceloR `Downward API` should work too but it is most complicated, and will hurt on the scale. – Michael Eino Jul 17 '18 at 09:32

1 Answers1

0

Well, I figured out that my application is a stateful and not stateless application, that requires fixed/stable hostname/storage etc...

I have decided to use the statefulset controller

references: