linux运维架构之路-k8s部署redis
Posted Demon
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux运维架构之路-k8s部署redis相关的知识,希望对你有一定的参考价值。
一、创建命名空间
apiVersion: v1
kind: Namespace
metadata:
name: dev
二、创建redis配置ConfigMap
apiVersion: v1 kind: ConfigMap metadata: namespace: dev name: redis-conf data: redis.conf: | bind 0.0.0.0 port 6379 #requirepass 111111 #设置认证密码 appendonly yes cluster-config-file nodes-6379.conf pidfile /redis/log/redis-6379.pid cluster-config-file /redis/conf/redis.conf dir /redis/data/ logfile /redis/log/redis-6379.log cluster-node-timeout 5000 protected-mode no
三、创建有状态应用StatefulSet,并把数据挂载到宿主机上
apiVersion: apps/v1 kind: StatefulSet metadata: name: redis namespace: dev spec: replicas: 1 serviceName: redis selector: matchLabels: name: redis template: metadata: labels: name: redis spec: initContainers: - name: init-redis image: 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: data mountPath: /redis/ containers: - name: redis image: hub.ityy.ultrapower.com.cn:5050/middleware/redis:4.0.6 imagePullPolicy: IfNotPresent command: - sh - -c - "exec redis-server /redis/conf/redis.conf" ports: - containerPort: 6379 name: redis protocol: TCP volumeMounts: - name: redis-config mountPath: /redis/conf/ - name: data mountPath: /redis/ volumes: - name: redis-config configMap: name: redis-conf - name: data hostPath: path: /app/ #挂载宿主机目录 nodeSelector: domain: dev #选择要部署的固定节点
四、创建Service对外暴露应用
kind: Service apiVersion: v1 metadata: namespace: dev labels: name: redis name: redis spec: type: NodePort ports: - name: redis port: 6379 targetPort: 6379 nodePort: 31379 selector: name: redis
以上是关于linux运维架构之路-k8s部署redis的主要内容,如果未能解决你的问题,请参考以下文章