linux运维、架构之路k8s部署redis [操作系统入门]
一、创建命名空间
apiVersion: v1kind: Namespace
metadata:
name: dev
二、创建redis配置ConfigMap
apiVersion: v1kind: ConfigMap
metadata:
namespace: devname: redis
-confdata:
redis.conf:
|bind
0.0.0.0port
6379#requirepass
111111 #设置认证密码appendonly yes
cluster
-config-file nodes-6379.confpidfile
/redis/log/redis-6379.pidcluster
-config-file /redis/conf/redis.confdir
/redis/data/logfile
/redis/log/redis-6379.logcluster
-node-timeout 5000protected-mode no
三、创建有状态应用StatefulSet,并把数据挂载到宿主机上
apiVersion: apps/v1kind: StatefulSet
metadata:
name: redis
namespace: devspec:
replicas:
1serviceName: redis
selector:
matchLabels:
name: redis
template:
metadata:
labels:
name: redis
spec:
initContainers:
- name: init-redisimage: hub.ityy.ultrapower.com.cn:
5050/middleware/busybox:1.1.1 #初始化容器镜像command: [
‘sh‘, ‘-c‘, ‘mkdir -p /redis/log/;mkdir -p /redis/conf/;mkdir -p /redis/data/‘]volumeMounts:
- name: datamountPath:
/redis/containers:
- name: redisimage: hub.ityy.ultrapower.com.cn:
5050/middleware/redis:4.0.6imagePullPolicy: IfNotPresent
command:
- sh- -c- "exec redis-server /redis/conf/redis.conf"ports:
- containerPort: 6379name: redis
protocol: TCP
volumeMounts:
- name: redis-configmountPath:
/redis/conf/- name: data
mountPath: /redis/
volumes:
- name: redis-config
configMap:
name: redis-conf
- name: data
hostPath:
path: /app/ #挂载宿主机目录
nodeSelector:
domain: dev #选择要部署的固定节点
四、创建Service对外暴露应用
kind: ServiceapiVersion: v1
metadata:
namespace: devlabels:
name: redis
name: redis
spec:
type: NodePort
ports:
- name: redisport:
6379targetPort:
6379nodePort:
31379selector:
name: redis
linux运维、架构之路-k8s部署redis
以上是 linux运维、架构之路k8s部署redis [操作系统入门] 的全部内容, 来源链接: utcz.com/z/519383.html