我刚刚设置了一个redis示例,但是我似乎无法让这两个容器相互通信,这个设置在本地机器上与docker compose一起工作,但似乎没有与kubernetes一起工作。
我的日志告诉我flask找不到服务,所以错误一定是我的配置文件
flask 代码:
rDB = redis.Redis(host='redis', port=6379, db=0)
flask 服务器:
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
redis示例:
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
1条答案
按热度按时间zzzyeukh1#
这是我在k8s中创建的redis集群服务。
如果你创建了那个服务。同一命名空间中的其他pod应该可以使用该主机名访问您的pod:
这意味着,在你的应用程序代码中,你已经更改了这一行: