Cloud/Kubernetes

Kubectl 이미지를 통해 Kube cluster에 접근하는 Pod

퐁스 2021. 1. 8. 16:02
kind: Pod
apiVersion: v1
metadata:
  name: kubectl
  labels:
    app: kubectl
spec:
  restartPolicy: Never
  affinity:
    nodeAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        nodeSelectorTerms:
          - matchExpressions:
              - key: node-role.kubernetes.io/master
                operator: Exists
  containers:
    - resources: {}
      name: kubectl
      securityContext:
        privileged: true
      volumeMounts:
        - name: kube-config
          mountPath: /root/.kube/
      tty: true
      image: viejo/kubectl
      command: ["kubectl", "get", "pod"]
  serviceAccount: default
  volumes:
    - name: kube-config
      hostPath:
        path: /home/$USER/.kube/
        type: ''

주의점

- pod를 띄우는 serviceaccount에 권한이 있어야 함

- command에 원하는 명령어 작성 (작성하지 않고 pod에 들어가서 해도 되나 cronjob을 위하여 이렇게 작성함)