[k8s] yaml 파일로 오브젝트 관리

곽동규·2024년 6월 22일

학습 및 실습 중

쿠버네티스 리소스는 yaml 파일 형태로 export가 가능하다
kube-neat를 사용하면 가독성 좋은 yaml 파일로 export 가능

[root@k8s-master01 ~]# kubectl get pod busybox -o yaml|kubectl neat
apiVersion: v1
kind: Pod
metadata:
  annotations:
    cni.projectcalico.org/containerID: 5abf61331b252c18bfb0e666d4fb07504072e168c12d61cc4e35229f4a432444
    cni.projectcalico.org/podIP: 10.1.79.73/32
    cni.projectcalico.org/podIPs: 10.1.79.73/32
  labels:
    run: busybox
  name: busybox
  namespace: default
spec:
  containers:
  - image: busybox
    name: busybox
    volumeMounts:
    - mountPath: /var/run/secrets/kubernetes.io/serviceaccount
      name: kube-api-access-7vt68
      readOnly: true
  preemptionPolicy: PreemptLowerPriority
  priority: 0
  serviceAccountName: default
  tolerations:
  - effect: NoExecute
    key: node.kubernetes.io/not-ready
    operator: Exists
    tolerationSeconds: 300
  - effect: NoExecute
    key: node.kubernetes.io/unreachable
    operator: Exists
    tolerationSeconds: 300
  volumes:
  - name: kube-api-access-7vt68
    projected:
      sources:
      - serviceAccountToken:
          expirationSeconds: 3607
          path: token
      - configMap:
          items:
          - key: ca.crt
            path: ca.crt
          name: kube-root-ca.crt
      - downwardAPI:
          items:
          - fieldRef:
              fieldPath: metadata.namespace
            path: namespace

yaml 파일로 쿠버네티스 오브젝트를 만드는 명령어로는 kubectl apply 와 kubectl create가 있다.
apply는 기존 오브젝트 수정이 가능하나, create는 기존에 생성한 오브젝트를 수정할 수 없다.

[root@k8s-master01 ~]# kubectl apply -f busybox-pod.yml

파드 리소스 사용량 제한 설정 가능

spec:
  containers:
  - image: busybox
    name: busybox
    resource:
      limits:
        memory: 512Mi
      requests:
        memory: 128Mi

쿠버네티스 공식 홈페이지에서 제공하는 service.yml 파일

apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  selector:
    app.kubernetes.io/name: MyApp
  ports:
    - protocol: TCP
      port: 80
      targetPort: 9376
- 쿠버네티스 오브젝트 yaml 파일은 AKMS(apiversion, kind, metadata, spec) 필드를 포함하고 들여쓰기상 첫번째에 위치한다.
- apiversion : 오브젝트를 생성하기 위해 사용하고 있는 쿠버네티스 api 버전 정보
- kind : 생성할 오브젝트의 종류
- metadata : 이름, uid, 네임스페이스를 포함해서 각 오브젝트를 식별할 데이터 지정
- spec :  오브젝트에 대한 상세 상태 지정

0개의 댓글