[kubernetes]-k8s部署单节点redis
导语:项目需要部署在k8s里需要运行一个3.0.7的redis 保存session首先创建redis.conf对应的cm文件redis-config.yaml---kind: ConfigMapapiVersion: v1metadata:name: redis-configlabels:app: redisdata:redis.conf: |-dir /srvport 6379bind 0.0.
·
导语:项目需要部署在k8s里 需要运行一个3.0.7的redis 保存session
首先创建redis.conf对应的cm文件
redis-config.yaml
---
kind: ConfigMap
apiVersion: v1
metadata:
name: redis-config
labels:
app: redis
data:
redis.conf: |-
dir /srv
port 6379
bind 0.0.0.0
appendonly yes
daemonize no
#protected-mode no
requirepass Hangzhou@123
pidfile /srv/redis-6379.pid
kubectl apply -f redis-config.yaml -n devops
如果redis数据需要持久化 可以用存储。我是session 丢了就丢了呗。
redis-deploy.yaml
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: redis
labels:
app: redis
spec:
replicas: 1
selector:
matchLabels:
app: redis
template:
metadata:
labels:
app: redis
spec:
containers:
- name: redis
image: redis:3.0.7
command:
- "sh"
- "-c"
- "redis-server /usr/local/redis/redis.conf"
ports:
- containerPort: 6379
resources:
limits:
cpu: 1000m
memory: 1024Mi
requests:
cpu: 1000m
memory: 1024Mi
livenessProbe:
tcpSocket:
port: 6379
initialDelaySeconds: 300
timeoutSeconds: 1
periodSeconds: 10
successThreshold: 1
failureThreshold: 3
readinessProbe:
tcpSocket:
port: 6379
initialDelaySeconds: 5
timeoutSeconds: 1
periodSeconds: 10
successThreshold: 1
failureThreshold: 3
volumeMounts:
- name: config
mountPath: /usr/local/redis/redis.conf
subPath: redis.conf
volumes:
- name: config
configMap:
name: redis-config
创建configmap和deployment
kubectl apply -f redis-config.yaml --force -n devops
kubectl apply -f redis-deploy.yaml -n devops --force
# 查看pod的ip
kubectl get pods -n devops -o wide
# 运行一个自删除的redis 容器 测试pod的连通性
docker run -it --rm redis:3.0.7 /bin/bash
# 使用reids-cli命令连接测试
测试密码设置没问题
redis-svc.yaml
apiVersion: v1
kind: Service
metadata:
name: redis
namespace: devops
labels:
app: redis
spec:
type: NodePort
ports:
- name: tcp
port: 6379
nodePort: 30379
selector:
app: redis
创建svc
kubectl apply -f redis-svc.yaml -n devops
测试连接node的端口测试
连接成功。
更多推荐
已为社区贡献84条内容
所有评论(0)