try:
_redis_client = Redis('redis')
print(_redis_client.info())
except Exception as e:
print(e)
version: "3"
services:
web:
build: .
ports:
- "8080:8080"
restart: always
redis:
image: redis:5-alpine
ports:
- "6379:6379"
volumes:
- "/data"
restart: always
apiVersion: apps/v1
kind: Deployment
metadata:
name: pytest
spec:
replicas: 1
template:
metadata:
labels:
app: pytest
spec:
containers:
- name: web
image: '..'
ports:
- containerPort: 8080
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: redis
spec:
spec:
volumes:
- name: redis-data
containers:
- name: redis
image: redis:5-alpine
ports:
- containerPort: 6379
protocol: TCP
volumeMounts:
- name: redis-data
mountPath: /data
selector:
matchLabels:
app: redis
---
apiVersion: v1
kind: Service
metadata:
name: web
spec:
type: NodePort
ports:
- name: "web"
port: 8080
selector:
app: pytest
---
apiVersion: v1
kind: Service
metadata:
name: redis
spec:
type: NodePort
ports:
- name: "redis"
port: 6379
selector:
app: redis
怎么连上 k8s 的 redis
1
qoo2019 2020-05-05 17:49:53 +08:00 via iPhone
最简单的 nodeport 映射个端口
|
2
zeron889 2020-05-06 12:22:27 +08:00
这个有两种方式,一个是走 cluster ip 的 svc,和走 nodeport 的主机暴露端口
|
3
julyclyde 2020-05-06 15:10:15 +08:00
运行 docker 的时候别用 NAT 模式
|