Kubernetes部署系列:Redis单机版

第一步:创建configmap

apiVersion: v1
kind: ConfigMap
metadata:
  name: redis-conf
  namespace: kube-public
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

第二步:创建pv

apiVersion: v1
kind: PersistentVolume
metadata:
  name: redis-pv
  namespace: kube-public
spec:
  capacity:
    storage: 1G
  accessModes:
    - ReadWriteMany
  storageClassName: redis-nfs
  nfs:
    path: /storage/nfsdata/redis  
	server: 192.168.194.104 

第三步:创建pvc

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: redis-pvc
  namespace: kube-public
spec:
  volumeName: redis-pv
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 1Gi
  storageClassName: redis-nfs

 第四步:创建pod

apiVersion: apps/v1
kind: Deployment
metadata:
  name: redis
  namespace: kube-public
spec:
  selector:
    matchLabels:
      name: redis
  template:
    metadata:
      labels:
        name: redis
    spec:
      initContainers:
      - name: init-redis
        image: 192.168.194.104:8080/library/busybox:latest  # 私有仓库
        command: ['sh', '-c', 'mkdir -p /redis/log/;mkdir -p /redis/conf/;mkdir -p /redis/data/']
        volumeMounts:
        - name: redis-pvc
          mountPath: /redis/
      containers:
      - name: redis
        image: 192.168.194.104:8080/library/redis:5.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: redis-pvc
          mountPath: /redis/
      volumes:
      - name: redis-config
        configMap:
          name: redis-conf
      - name: redis-pvc
        persistentVolumeClaim:
          claimName: redis-pvc

第五步:创建svc

kind: Service
apiVersion: v1
metadata:
  labels:
    name: redis
  name: redis
  namespace: kube-public
spec:
  type: NodePort
  ports:
  - name: redis
    port: 6379
    targetPort: 6379
    nodePort: 30022
  selector:
    name: redis

 第六步:验证

Kubernetes部署系列:Redis单机版_第1张图片

你可能感兴趣的:(Kubernetes系列,kubernetes,redis)