名称解析redis暂时失败 [英] Temporary failure in name resolution redis

查看:360
本文介绍了名称解析redis暂时失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近一直在学习Kubernetes.而且我正在尝试使用redis,但出现以下错误:

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

Error:Error -3 connecting to redis:6379. Temporary failure in name resolution.

我正在使用:

  conn = redis.StrictRedis(host='redis', port=6379)

docker composer :

     redis: 
        image: redis:alpine 
        ports:
          - "6379:6379" 

redis-deploy.yml

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

服务重做:

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

kubectl get svc

redis            NodePort    10.152.183.209   <none>        6379:32649/TCP   7m31s

编辑:映像是从docker提取的,这是部署文件之一.

the image is pulling from docker, here is one of the deployment files.

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

推荐答案

我将下面的yaml文件用于redis(我从

I used the yaml file below for redis (that I got and modified a bit from How to deploy a node.js with redis on kubernetes?):

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

使用yaml文件进行部署后,当您运行microk8s.kubectl get services时,应该显示以下响应:

After deploying with the yaml file, when you run microk8s.kubectl get services, you should a response like below:

NAME         TYPE        CLUSTER-IP       EXTERNAL-IP    PORT(S)          AGE
kubernetes   ClusterIP   10.152.183.1     <none>         443/TCP          14d
redis        NodePort    10.152.183.114   192.168.2.146   6379:32000/TCP   14m

在我的情况下,microk8s部署在192.168.2.146上的本地VM(在externalIPs中进行了描述.因此,使用此设置,我可以从本地VM(CentOS)和父计算机访问redis (Windows).另外,如果像我这样将microk8s部署在远程服务器上,则还需要打开端口6379,以便您的代码可以远程访问它.要测试来自VM的连接,我使用了以下命令:

In my case, microk8s is deployed on a local VM that is on 192.168.2.146 (which is described in externalIPs. 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:

echo PING | nc 192.168.2.146 6379
echo PING | nc localhost 32000

对于这两个命令,您都应该获得响应:

For both commands you should get the response:

+PONG

在Windows中,您可以使用PowerShell并使用命令tnc 192.168.2.146 -port 6379来测试连接性.您应该收到如下响应:

From Windows you can use PowerShell and use the command tnc 192.168.2.146 -port 6379 to test connectivity. You should get a response like below:

ComputerName     : 192.168.2.146
RemoteAddress    : 192.168.2.146
RemotePort       : 6379
InterfaceAlias   : <alias>
SourceAddress    : <source_ip>
TcpTestSucceeded : True

这篇关于名称解析redis暂时失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆