๐ŸŽฏ ืžื˜ืจืช ื”ืชืจื’ื•ืœ

ื‘ืฉืœื‘ ื–ื” ื ื‘ื ื” ื‘ืคื•ืขืœ StatefulSet ื•ื ืจืื”:


ื—ืœืง 1 โ€” ื”ืชื—ืœื” ืžื”ื’ื“ืจืช BusyBox ืงื•ื“ืžืช

ืื‘ืœ ืœื ืžืฉืชืžืฉื™ื ื‘ื–ื” ื›ืžื• ืฉื”ื•ื.


ื—ืœืง 2 โ€” ื™ืฆื™ืจืช StatefulSet

ื ื™ืฆื•ืจ ืงื•ื‘ืฅ:

vi stateful-set.yaml

ื•ื ื›ื ื™ืก:

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: demo-statefulset

spec:
  serviceName: busybox   # This can be any name (as mentioned in the lecture)

  replicas: 2            # We want two replicas

  selector:
    matchLabels:
      app: busybox       # Defines which pods are managed by this StatefulSet

  template:
    metadata:
      labels:
        app: busybox     # Must match the selector above

    spec:
      containers:
        - name: busybox
          image: busybox:1.36.1
          command: ["sh", "-c", "sleep 3600"]

          volumeMounts:
            - name: local-storage
              mountPath: /mnt/local   # Mounted inside container

  volumeClaimTemplates:
    - metadata:
        name: local-storage           # This name MUST match volumeMounts.name

      spec:
        accessModes:
          - ReadWriteOnce

        storageClassName: local-storage

        resources:
          requests:
            storage: 128Mi