我刚刚设置了一个redis实例,但是我似乎无法让两个容器彼此对话,安装程序在本地计算机上使用docker-compose进行了工作,但似乎不适用于kubernetes。
我的日志告诉我flask无法找到该服务,因此错误必须是我的配置文件
rDB = redis.Redis(host='redis', port=6379, db=0)
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
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
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
答案 0 :(得分:1)
这是我在k8s中创建我的redis集群的服务。
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
如果创建该服务。使用该主机名的同一个命名空间中的其他Pod应该可以访问您的Pod:
my-redis-svc.default.svc.cluster.local
这意味着,在您的应用代码中,您已更改了该行:
rDB = redis.Redis(host='my-redis-svc.default.svc.cluster.local', port=6379, db=0)