<p>I've just setup a redis instance however I can't seem to get the two containers to talk to each-other, the setupworks over local machine with docker-compose but does not seem to be working with kubernetes.</p>
<p>My logs tell me flask can't find the service, so the error must be my configuration files</p>
<h1>Flask code:</h1>
<pre class="lang-py prettyprint-override"><code>rDB = redis.Redis(host='redis', port=6379, db=0)
</code></pre>
<h1>Flask server:</h1>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1beta2
kind: Deployment
metadata:
  name: dashboard
  namespace: default
  labels:
    run: dashboard
spec:
  replicas: 2
  selector:
    matchLabels:
      run: dashboard
  template:
    metadata:
      labels:
        run: dashboard
    spec:
      containers:
      - image: gcr.io/******/dashboard_server:v102
        name: dashboard
        livenessProbe:
          httpGet:
            path: /
            port: 8000
          initialDelaySeconds: 300
          timeoutSeconds: 5
          periodSeconds: 300
          failureThreshold: 3
        ports:
          - containerPort: 8000
            name: http
            protocol: TCP
</code></pre>
<h1>Redis instance:</h1>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1 #  for k8s versions before 1.9.0 use apps/v1beta2  and before 1.8.0 use extensions/v1beta1
kind: Deployment
metadata:
  name: redis
  namespace: default
spec:
  selector:
    matchLabels:
      run: dashboard
      role: master
      tier: backend
  replicas: 1
  template:
    metadata:
      labels:
        run: dashboard
        role: master
        tier: backend
    spec:
      containers:
      - name: redis
        image: redis  # or just image: redis
        resources:
          requests:
            cpu: 100m
            memory: 100Mi
        ports:
        - containerPort: 6379
</code></pre>
<h1>Service code</h1>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Service
metadata:
  name: dash-service
  namespace: default
  labels:
    run: frontend
spec:
  selector:
    run: dashboard
  ports:
    - name: http
      protocol: TCP
      port: 80
      targetPort: 8000
  type: ClusterIP
</code></pre>

<p>Here is a service I created my redis cluster inside k8s.</p>

<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Service
metadata:
  labels:
    app: redis
  name: my-redis-svc
  namespace: default
spec:
  ports:
  - name: redis
    port: 6379
    targetPort: 6379
    protocol: TCP
  selector:
    app: redis
  type: ClusterIP
</code></pre>

<p>If you create that service. Your pods should be accessible by other pods in same namespace using that hostname : </p>

<pre><code>my-redis-svc.default.svc.cluster.local
</code></pre>

<p>That means, in your app code you have change that line :</p>

<pre class="lang-py prettyprint-override"><code>rDB = redis.Redis(host='my-redis-svc.default.svc.cluster.local', port=6379, db=0)
</code></pre>
