K8S 搭建 redis:5.0.5-alpine

deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: redis-spot
  namespace: spot-standard
spec:
  selector:
    matchLabels:
      app: redis-spot
  replicas: 1
  template:
    metadata:
      labels:
        app: redis-spot
    spec:
      terminationGracePeriodSeconds: 60
      containers:
      - name: redis
        imagePullPolicy: IfNotPresent
        image: docker.io/library/redis:5.0.5-alpine
        args:
        - '--requirepass "huidiancloud"'
        resources:
          requests:
            cpu: 500m
            memory: 1024Mi
          limits:
            cpu: 1000m
            memory: 3096Mi
        ports:
        - containerPort: 6379
          name: tcp
        livenessProbe:
          tcpSocket:
            port: 6379
          initialDelaySeconds: 180
          periodSeconds: 60
        volumeMounts:
        - mountPath: /etc/localtime
          readOnly: false 
          name: time-data
        - mountPath: /data
          name: pvc-nas-redis-spot
      volumes:
      - name: time-data 
        hostPath: 
          path: /usr/share/zoneinfo/Asia/Shanghai
      - name: pvc-nas-redis-spot
        persistentVolumeClaim:
          claimName: pvc-nas-redis-spot
      initContainers:
      - image: docker.io/library/alpine:3.11
        command: ["/sbin/sysctl", "-w", "net.core.somaxconn=2048"]
        name: redis-init
        securityContext:
          privileged: true

nas.yaml

apiVersion: v1
kind: PersistentVolume
metadata:
  name: spot-standard-pv-nas-redis-spot
  labels:
    alicloud-pvname: spot-standard-pv-nas-redis-spot
spec:
  capacity:
    storage: 20Gi
  accessModes:
    - ReadWriteMany
  csi:
    driver: nasplugin.csi.alibabacloud.com
    volumeHandle: spot-standard-pv-nas-redis-spot
    volumeAttributes:
      server: "214ce4b610-quv89.cn-shenzhen.nas.aliyuncs.com"
      path: "/spot-standard/redis-spot"
  mountOptions:
  - nolock,tcp,noresvport
  - vers=3

---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: pvc-nas-redis-spot
  namespace: spot-standard
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 20Gi
  selector:
    matchLabels:
      alicloud-pvname: spot-standard-pv-nas-redis-spot

svc.yaml

kind: Service
apiVersion: v1
metadata:
  labels:
    app: redis-spot
  name: redis-spot
  namespace: spot-standard
spec:
  ports:
  - port: 6379
    targetPort: 6379
  selector:
    app: redis-spot

svc-nodeport.yaml

kind: Service
apiVersion: v1
metadata:
  labels:
    app: redis-spot
  name: redis-spot-nodeport
  namespace: spot-standard
spec:
  type: NodePort
  ports:
  - port: 6379
    targetPort: 6379
    nodePort: 30079
  selector:
    app: redis-spot

查看

[root@test-k8s-node-01 redis]# kubectl get svc -n spot-standard 
NAME                  TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
redis-spot            ClusterIP   192.168.141.1    <none>        6379/TCP         117d
redis-spot-nodeport   NodePort    192.168.16.180   <none>        6379:30079/TCP   117d

[root@test-k8s-node-01 redis]# kubectl get pod -n spot-standard 
NAME                                          READY   STATUS    RESTARTS   AGE
redis-spot-5cd8cb9f86-ghhtz                   1/1     Running   0          97d
posted @ 2021-09-27 17:04  klvchen  阅读(322)  评论(0)    收藏  举报