How to configure Service in K8S to set host name in *_SERVICE_HOST variable instead of IP address

7/12/2019

I have PODS(server and client) in K8S cluster which communicate using SSL/sockets. Server POD has Service attached to it. So whenever Client POD comes up SERVER_SERVICE_HOST and SERVER_SERVICE_PORT environment variables are added to Client POD. Its working fine without SSL. But when SSL is used SSL handshake error is coming as client gets hostname in SSL certificate but SERVER_SERVICE_HOST has IP address in it. Is there a way to make K8S fill in hostname in SERVER_SERVICE_HOST instead of IP address ?

-- Chandu
kubernetes
service
ssl

1 Answer

7/12/2019

Complementing previous answer, you can set environment variables in the spec of a pod by simply adding them to the YAML definition of the pod.

From your question, I'm under the impression that SERVER_SERVICE_HOST and SERVER_SERVICE_PORT are included in the YAML definitions that you're deploying. You might be able to change them in the definitions.

An additional thing to have in mind is that all the objects within the cluster depend on the internal DNS records set in either, coreDNS or kube-dns, and those records are automatically generated and added to the resolv.conf file in each pod.

This is important to consider if your SSL authentication relies on specific, certificate-tied hostnames, as these might be different from what you expect.

-- yyyyahir
Source: StackOverflow