Kubernetes pod/deploy/sts/ds example
February 26, 2023

Pod with PV emptyDir and hostPath

Пример пода с emptyDir. С дефолтными настройками

cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
  name: cam-nginx
  namespace: default
  labels:
    app: nginx
    env: prod
  annotations:
    author: cameda
spec:
  containers:
  - name: cam-nginx
    image: nginx:latest
    imagePullPolicy: IfNotPresent
    resources:
      requests:
        cpu: 300m
        memory: 300Mi
      limits:
        memory: 500Mi
    ports:
    - containerPort: 80
    - containerPort: 443
    livenessProbe:
      failureThreshold: 10
      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: 7
    volumeMounts:
    - name: cam-volume
      mountPath: /mnt/cameda
  restartPolicy: OnFailure
  tolerations:
  - key: "cam"
    operator: "Exists"
    effect: "NoSchedule"
  - key: "cam"
    operator: "Exists"
    effect: "NoExecute"
  volumes:
  - name: cam-volume
    emptyDir: {}
EOF

Пример пода с emptyDir и хранением данных в памяти.

cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
  name: cam-nginx
  namespace: default
  labels:
    app: nginx
    env: prod
  annotations:
    author: cameda
spec:
  containers:
  - name: cam-nginx
    image: nginx:latest
    imagePullPolicy: IfNotPresent
    resources:
      requests:
        cpu: 300m
        memory: 300Mi
      limits:
        memory: 500Mi
    ports:
    - containerPort: 80
    - containerPort: 443
    livenessProbe:
      failureThreshold: 10
      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: 7
    volumeMounts:
    - name: cam-volume
      mountPath: /mnt/cameda
  restartPolicy: OnFailure
  tolerations:
  - key: "cam"
    operator: "Exists"
    effect: "NoSchedule"
  - key: "cam"
    operator: "Exists"
    effect: "NoExecute"
  volumes:
  - name: cam-volume
    emptyDir:
      medium: Memory
      sizeLimit: 100m
EOF

Пример пода с hostPath и типом Directory.

cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
  name: cam-nginx
  namespace: default
  labels:
    app: nginx
    env: prod
  annotations:
    author: cameda
spec:
  containers:
  - name: cam-nginx
    image: nginx:latest
    imagePullPolicy: IfNotPresent
    resources:
      requests:
        cpu: 300m
        memory: 300Mi
      limits:
        memory: 500Mi
    ports:
    - containerPort: 80
    - containerPort: 443
    livenessProbe:
      failureThreshold: 10
      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: 7
    volumeMounts:
    - name: cam-volume
      mountPath: /mnt/cameda
  restartPolicy: OnFailure
  nodeName: cl14iev9l04rfqleuqa5-iguw
  tolerations:
  - key: "cam"
    operator: "Exists"
    effect: "NoSchedule"
  - key: "cam"
    operator: "Exists"
    effect: "NoExecute"
  volumes:
  - name: cam-volume
    hostPath:
      # directory location on host
      path: /mnt/cam
      type: Directory
EOF

Другие типы в hostPath: BlockDevice, File, Socket.