一、pv

apiVersion: v1
kind: PersistentVolume
metadata:
  name: redis-pv 
  labels:
    app: redis
spec:
  capacity:
    storage: 1Gi
  volumeMode: Filesystem  
  storageClassName: redis-storage 
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  nfs:
    path: /home/data/redis
    server: k8snfs

二、StatefulSet

 ##  kubectl apply -f  redis.yaml
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: redis
spec:
  selector:
    matchLabels:
      app: redis
  serviceName: "redis"
  replicas: 1
  template:
    metadata:
      labels:
        app: redis
    spec:    
      terminationGracePeriodSeconds: 10
      containers:
        - name: redis
          image: redis:latest
          imagePullPolicy: IfNotPresent
          command: ["/bin/sh","-c","redis-server /redis/redis.conf "]
          ports:
            - containerPort: 6379
          volumeMounts:
            - name: redis-persistent-storage
              mountPath: /redis
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: nodeType
                operator: In
                values:
                - middleware
  volumeClaimTemplates:
    - metadata:
        name: redis-persistent-storage
      spec:
        storageClassName: redis-storage
        accessModes:
          - ReadWriteOnce
        resources:
          requests:
            storage: 1Gi
Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐