<p>I have been learning Kubernetes lately. And I'm trying to use redis but I am getting the following error:</p>

<pre><code>Error:Error -3 connecting to redis:6379. Temporary failure in name resolution.
</code></pre>

<p>I'm using:</p>

<pre><code>  conn = redis.StrictRedis(host='redis', port=6379)
</code></pre>

<p><strong>docker composer</strong>:</p>

<pre><code>     redis: 
        image: redis:alpine 
        ports:
          - "6379:6379" 
</code></pre>

<p><strong>redis-deploy.yml</strong></p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: redis-deploy
spec:
  selector:
    matchLabels:
      app: redis
  template:
    metadata:
      labels:
        app: redis
    spec:
      containers:
      - name: redis
        image: redis:alpine
        ports:
        - containerPort: 6379
</code></pre>

<p><strong>service redis:</strong></p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  labels:
    app: redis
  name: redis
spec:
  selector:
    app: redis
  type: NodePort
  ports:
  - port: 6379
    protocol: TCP
</code></pre>

<p><strong>kubectl get svc</strong></p>

<pre><code>redis            NodePort    10.152.183.209   &lt;none&gt;        6379:32649/TCP   7m31s
</code></pre>

<p><strong>EDIT:</strong> the image is pulling from docker, here is one of the deployment files.</p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: greeter-client-deploy
spec:
  replicas: 10
  selector:
    matchLabels:
      app: greeter-client
  minReadySeconds: 10
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 1
      maxSurge: 1
  template:
    metadata:
      labels:
        app: greeter-client
    spec:
      containers:
      - name: greeter-client
        image: seancork92/greeter_client:latest
</code></pre>

<p>I used the yaml file below for redis (that I got and modified a bit from <a href="https://stackoverflow.com/questions/53031852/how-to-deploy-a-node-js-with-redis-on-kubernetes">How to deploy a node.js with redis on kubernetes?</a>):</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  labels:
    app: redis
  name: redis
spec:
  externalIPs:
  - 192.168.2.146
  selector:
    app: redis
  type: NodePort
  ports:
  - port: 6379
    nodePort: 32000
    protocol: TCP
    targetPort: 6379
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: redis-deploy
spec:
  selector:
    matchLabels:
      app: redis
  template:
    metadata:
      labels:
        app: redis
    spec:
      containers:
      - name: redis
        image: redis:latest
        ports:
        - containerPort: 6379
        volumeMounts:
        - name: data
          mountPath: /data
          readOnly: false
      volumes:
      - name: data
        persistentVolumeClaim:
          claimName: redis-data          
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: redis-data
  labels:
    app: redis
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 100Mi
</code></pre>
<p>After deploying with the yaml file, when you run <code>microk8s.kubectl get services</code>, you should a response like below:</p>
<pre><code>NAME         TYPE        CLUSTER-IP       EXTERNAL-IP    PORT(S)          AGE
kubernetes   ClusterIP   10.152.183.1     &lt;none&gt;         443/TCP          14d
redis        NodePort    10.152.183.114   192.168.2.146   6379:32000/TCP   14m
</code></pre>
<p>In my case, microk8s is deployed on a local VM that is on 192.168.2.146 (which is described in <code>externalIPs</code>. So with this setup I could access redis from both the local VM (CentOS) and from the parent machine (Windows). Also, if microk8s is deployed on a remote server like in my case, you also need to open port 6379 so your code can access it remotely. To test the connectivity from the VM I used the commands below:</p>
<pre><code>echo PING | nc 192.168.2.146 6379
echo PING | nc localhost 32000
</code></pre>
<p>For both commands you should get the response:</p>
<pre><code>+PONG
</code></pre>
<p>From Windows you can use PowerShell and use the command <code>tnc 192.168.2.146 -port 6379</code> to test connectivity. You should get a response like below:</p>
<pre><code>ComputerName     : 192.168.2.146
RemoteAddress    : 192.168.2.146
RemotePort       : 6379
InterfaceAlias   : &lt;alias&gt;
SourceAddress    : &lt;source_ip&gt;
TcpTestSucceeded : True
</code></pre>
