Kubernetes pod/deploy/sts/ds example
March 4, 2023
Deployment/Pod/StatefulSet with PV hostPath
Примеры конфигурации Pod/Deployment/StatefulSet с PV hostPath. Примеры разбираются на кластере с одним мастером и одной воркер нодой.
На определённой ноде кластера создаём папку /mnt/cam:
mkdir /mnt/cam
cat <<EOF | kubectl apply -f - apiVersion: v1 kind: Pod metadata: name: cameda-nginx namespace: default labels: app: nginx env: prod annotations: author: cameda spec: containers: - name: cameda-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 volumes: - name: cam-volume hostPath: # directory location on host path: /mnt/cam type: Directory EOF
cat <<EOF | kubectl apply -f - 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 hostPath: # directory location on host path: /mnt/cam type: Directory EOF
cat <<EOF | kubectl apply -f - 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 hostPath: # directory location on host path: /mnt/cam type: Directory EOF