在K8S上部署redis
如 在K8S上部署mysql 所述,auth-server、user-center、api-gateway 都需要使用 redis 服务,本文描述如何使用 Kuboard 在 Kubernetes 上部署 redis。
本文将使用 redis官方镜像 进行部署。
部署redis
在 Kuboard 界面进入名称空间 (自己的命令空间),点击 创建工作负载 按钮,并填写表单,如下图所示:
基本信息
容器信息
- 容器启动检查探针
- 容器存活检查探针
存储挂载
- 配置字典
dir /data #数目录
port 6379 #指定端口
bind 0.0.0.0 #允许外部访问
appendonly yes #开启持久化
protected-mode no
requirepass 123qwe## #密码
高级设置
服务/应用路由
最后点击保存。
命令行配置文件如下
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
annotations: {}
labels:
k8s.kuboard.cn/layer: db
k8s.kuboard.cn/name: redis-dev
name: redis-dev
namespace: sca-dev
resourceVersion: '311600'
spec:
podManagementPolicy: Parallel
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
k8s.kuboard.cn/layer: db
k8s.kuboard.cn/name: redis-dev
serviceName: redis-dev
template:
metadata:
creationTimestamp: null
labels:
k8s.kuboard.cn/layer: db
k8s.kuboard.cn/name: redis-dev
spec:
containers:
- command:
- redis-server
- /usr/local/etc/redis/redis.conf
image: 'redis:7.2.0'
imagePullPolicy: IfNotPresent
livenessProbe:
failureThreshold: 3
initialDelaySeconds: 20
periodSeconds: 10
successThreshold: 1
tcpSocket:
port: 6379
timeoutSeconds: 1
name: redis
ports:
- containerPort: 6379
protocol: TCP
resources:
limits:
cpu: '2'
memory: 2000Mi
requests:
cpu: 100m
memory: 200Mi
startupProbe:
failureThreshold: 3
initialDelaySeconds: 30
periodSeconds: 10
successThreshold: 1
tcpSocket:
port: 6379
timeoutSeconds: 1
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /usr/local/etc/redis/redis.conf
name: volume-r4x5e
subPath: redis.conf
- mountPath: /data
name: volume-868k4
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
volumes:
- configMap:
defaultMode: 420
name: redis-config
name: volume-r4x5e
- name: volume-868k4
persistentVolumeClaim:
claimName: redis-pvc-d
updateStrategy:
rollingUpdate:
partition: 0
type: RollingUpdate
---
apiVersion: v1
kind: Service
metadata:
annotations: {}
labels:
k8s.kuboard.cn/layer: db
k8s.kuboard.cn/name: redis-dev
name: redis-dev
namespace: sca-dev
resourceVersion: '166707'
spec:
clusterIP: 10.233.159.49
clusterIPs:
- 10.233.159.49
externalTrafficPolicy: Cluster
internalTrafficPolicy: Cluster
ipFamilies:
- IPv4
ipFamilyPolicy: SingleStack
ports:
- name: d5rwyk
nodePort: 32702
port: 6379
protocol: TCP
targetPort: 6379
selector:
k8s.kuboard.cn/layer: db
k8s.kuboard.cn/name: redis-dev
sessionAffinity: ClientIP
sessionAffinityConfig:
clientIP:
timeoutSeconds: 10800
type: NodePort