Kubernetes pod/deploy/sts/ds example
March 4, 2023

Deployment/Pod/Statefulset c PV local

Установим провизионер.

kubectl apply -f https://raw.githubusercontent.com/rancher/local-path-provisioner/master/deploy/local-path-storage.yaml

Pod.

cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: local-path-pvc
  namespace: default
  labels:
    app: pvc-nginx
  annotations:
    author: cameda
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: local-path
  resources:
    requests:
      storage: 2Gi
---
apiVersion: v1
kind: Pod
metadata:
  name: cameda-nginx
  namespace: default
  labels:
    app: camNginx
  annotations:
    author: cameda
spec:
  containers:
  - name: cameda-nginx
    image: nginx:latest
    imagePullPolicy: IfNotPresent
    resources:
      requests:
        cpu: 300m
        memory: 500Mi
      limits:
        memory: 800Mi
    ports:
      - containerPort: 80
      - containerPort: 443
    livenessProbe:
      failureThreshold: 3
      successThreshold: 1
      httpGet:
        path: /
        port: 80
      periodSeconds: 10
      timeoutSeconds: 1
      initialDelaySeconds: 5
    readinessProbe:
      failureThreshold: 3
      successThreshold: 1
      exec:
        command:
        - curl
        - http://127.0.0.1:80
      periodSeconds: 10
      timeoutSeconds: 1
      initialDelaySeconds: 5
    volumeMounts:
    - name: dir-volume
      mountPath: /dir      
  volumes:
  - name: dir-volume
    persistentVolumeClaim:
      claimName: local-path-pvc
EOF

Deployment.

cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: local-path-pvc
  namespace: default
  labels:
    app: pvc-nginx
  annotations:
    author: cameda
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: local-path
  resources:
    requests:
      storage: 2Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: cam-nginx
  namespace: default
  labels:
    app: cam-nginx
  annotations:
    author: cameda
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
    type: RollingUpdate  
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
        - name: cam-nginx
          image: nginx:latest
          imagePullPolicy: IfNotPresent
          resources:
            requests:
              cpu: 250m
              memory: 300Mi
            limits:
              memory: 600Mi 
          ports:
            - containerPort: 80
            - containerPort: 443
          volumeMounts:
          - name: cameda-volume
            mountPath: /cameda             
      volumes:
      - name: cameda-volume
        persistentVolumeClaim:
          claimName: local-path-pvc
EOF

StatefulSet.

cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: local-path-pvc
  namespace: default
  labels:
    app: pvc-redis
  annotations:
    author: cameda
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: local-path
  resources:
    requests:
      storage: 2Gi
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: cam-redis
  namespace: default
  labels:
    app: cam-redis
  annotations:
    author: cameda
spec:
  serviceName: cam-redis
  replicas: 1
  selector:
    matchLabels:
      app: redis
  template:
    metadata:
      labels:
        app: redis
    spec:
      containers:
      - name: redis
        image: redis:latest
        imagePullPolicy: IfNotPresent
        resources:
          requests:
            cpu: 1
            memory: 2Gi
          limits:
            memory: 3Gi
        volumeMounts:
          - name: cameda-volume
            mountPath: /cameda           
        ports:
         - containerPort: 6379
         - containerPort: 26379
         - containerPort: 80
      volumes:
      - name: cameda-volume
        persistentVolumeClaim:
          claimName: local-path-pvc
EOF