faith0007 / capstone-order-3team

0 stars 0 forks source link

Persistent Volume & Self-healing (liveness probe) #5

Open yejeeann opened 1 year ago

yejeeann commented 1 year ago

Persistent Volume

EFS(Elastic File System) 사용한 Persistent Volume 설정

1. EFS 생성

image image

2. EFS 계정 생성 및 Role 바인딩

$ kubectl apply -f efs-sa.yaml

apiVersion: v1
kind: ServiceAccount
metadata:
  name: efs-provisioner

image

kubectl apply -f efs-rbac.yaml

kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: efs-provisioner-runner
rules:
  - apiGroups: [""]
    resources: ["persistentvolumes"]
    verbs: ["get", "list", "watch", "create", "delete"]
  - apiGroups: [""]
    resources: ["persistentvolumeclaims"]
    verbs: ["get", "list", "watch", "update"]
  - apiGroups: ["storage.k8s.io"]
    resources: ["storageclasses"]
    verbs: ["get", "list", "watch"]
  - apiGroups: [""]
    resources: ["events"]
    verbs: ["create", "update", "patch"]
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: run-efs-provisioner
subjects:
  - kind: ServiceAccount
    name: efs-provisioner
    namespace: default
roleRef:
  kind: ClusterRole
  name: efs-provisioner-runner
  apiGroup: rbac.authorization.k8s.io
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: leader-locking-efs-provisioner
rules:
  - apiGroups: [""]
    resources: ["endpoints"]
    verbs: ["get", "list", "watch", "create", "update", "patch"]
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: leader-locking-efs-provisioner
subjects:
  - kind: ServiceAccount
    name: efs-provisioner
roleRef:
  kind: Role
  name: leader-locking-efs-provisioner
  apiGroup: rbac.authorization.k8s.io

3. EFS Provisioner 배포

kubectl apply -f efs-provisioner-deploy.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: efs-provisioner
  namespace: mall
spec:
  replicas: 1
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app: efs-provisioner
  template:
    metadata:
      labels:
        app: efs-provisioner
    spec:
      serviceAccount: efs-provisioner
      containers:
        - name: efs-provisioner
          image: quay.io/external_storage/efs-provisioner:latest
          env:
            - name: FILE_SYSTEM_ID
              value: fs-0aaccb328f84992df
            - name: AWS_REGION
              value: eu-west-3
            - name: PROVISIONER_NAME
              value: my-aws.com/aws-efs
          volumeMounts:
            - name: pv-volume
              mountPath: /persistentvolumes
      volumes:
        - name: pv-volume
          nfs:
            server: fs-0aaccb328f84992df.efs.eu-west-3.amazonaws.com
            path: /

image

4. StorageClass 생성

kubectl apply -f efs-provisioner-deploy.yaml

kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: aws-efs
provisioner: my-aws.com/aws-efs

image

5. PVC(PersistentVolumeClaim) 생성

kubectl apply -f volume-PVC.yaml

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: aws-efs
  labels:
    app: test-pvc
spec:
  accessModes:
  - ReadWriteMany
  resources:
    requests:
      storage: 1Mi
  storageClassName: aws-efs

image

6. order pod 에 pvc 적용

kubectl apply -f deployment.yaml

          volumeMounts:
          - mountPath: "/mnt/aws"
            name: volume
      volumes:
        - name: volume
          persistentVolumeClaim:
            claimName: aws-efs

image

image

Self-healing (liveness probe)

order pod 실행 후 /tmp 디렉토리 healthy 체크하여 처리

/order/kubernetes/deployment.yaml

          livenessProbe:
            exec:
              command:
              - cat
              - /tmp/healthy
            initialDelaySeconds: 30
            timeoutSeconds: 2
            periodSeconds: 5
            failureThreshold: 10

order pod 생성

image

order pod /tmp/health 삭제

image

/tmp/health 삭제 후 order pod restart 확인

image