zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    SQL中的max()函数用法
    C#多线程
    C#操作redis
    spring+mybatis 多数据库事务
    实战项目中 :一个业务对多个数据库操作的同步的处理办法(要么都成功,要么都失败)Threadlocal 数据库事务
    redis之数据操作详解
    C# 两个数组取交集/补集 Intersect()
    MySQL创建索引
    MySQL每日执行
    MySQL删除重复数据
  • 原文地址:https://www.cnblogs.com/yanxinjiang/p/13974715.html
Copyright © 2011-2022 走看看