码迷,mamicode.com
首页 > 系统相关 > 详细

linux运维、架构之路-k8s部署redis

时间:2020-11-19 12:54:44      阅读:14      评论:0      收藏:0      [点我收藏+]

标签:pre   pid   template   toc   version   设置   names   配置   pps   

一、创建命名空间

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

标签:pre   pid   template   toc   version   设置   names   配置   pps   

原文地址:https://www.cnblogs.com/yanxinjiang/p/13974715.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!