<p>I am running Redis via Helm on Kubernetes and wondering how I reference the master pod from my application which is also running inside of Kubernetes as a pod. Helm is nice enough to create <code>ClusterIP</code> services, but I am still unclear in my application what I put to always reference the master:</p>

<pre><code>MacBook-Pro ➜  api git:(master) ✗ kubectl get services
NAME                           TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
ignoble-hyena-redis-master     ClusterIP   10.100.187.188   &lt;none&gt;        6379/TCP         5h21m
ignoble-hyena-redis-slave      ClusterIP   10.100.236.164   &lt;none&gt;        6379/TCP         5h21m
</code></pre>

<pre><code>MacBook-Pro ➜  api git:(master) ✗ kubectl describe service ignoble-hyena-redis-master
Name:              ignoble-hyena-redis-master
Namespace:         default
Labels:            app=redis
                   chart=redis-9.0.1
                   heritage=Tiller
                   release=ignoble-hyena
Annotations:       &lt;none&gt;
Selector:          app=redis,release=ignoble-hyena,role=master
Type:              ClusterIP
IP:                10.100.187.188
Port:              redis  6379/TCP
TargetPort:        redis/TCP
Endpoints:         192.168.34.46:6379
Session Affinity:  None
Events:            &lt;none&gt;
</code></pre>

<p>Do I use: <code>redis://my-password@ignoble-hyena-redis-master:6379</code>. That seems fragile as the pod name changes every time I redeploy the Helm chart. What is the recommended way to handle internal service discovery within the Kubernetes cluster?</p>

Justin
<p>You should <a href="https://helm.sh/docs/developing_charts/#charts" rel="nofollow noreferrer">package your application as a Helm chart</a>.  This basically involves running <code>helm create</code>, then copying your existing deployment YAML into the <code>templates</code> directory.  <a href="https://helm.sh/docs/developing_charts/#chart-dependencies" rel="nofollow noreferrer">Charts can have dependencies</a> and so you can declare that your application needs Redis.  Using the version in the <a href="https://github.com/helm/charts" rel="nofollow noreferrer">standard Helm charts repository</a> you can say something like</p>

<pre><code># I am requirements.yaml
- name: redis
  version: ~9.0.2
  repository: https://kubernetes-charts.storage.googleapis.com
</code></pre>

<p>The important detail here is that your application and its Redis will have the same Helm release name -- if your application is <code>ignoble-hyena-myapp</code> then its Redis will be <code>ignoble-hyena-redis-master</code>.  You can set this in your deployment YAML spec using templates</p>

<pre><code>env:
  - name: REDIS_HOST
    value: {{ .Release.Name }}-redis-master
</code></pre>

<p>Because of the way Kubernetes works internally, even if you <code>helm upgrade</code> your chart to a newer image tag, it won't usually touch the Redis.  Helm will upload a new version of the Redis artifacts that looks exactly the same as the old one, and Kubernetes will take no action.</p>
