Infra Architecture/Kubernetes

[K8S kubectl] --dry-run 옵션

검은 까마귀 2024. 2. 25. 14:54
$ kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...]

 

kubectl의 run명령어 옵션중에는 --dry-run 옵션이 있습니다. 실제로 사전에 검색을 해보았습니다.

영어에서 군대 용어중 하나인데 실탄 없이하는 모의 연습을 이야기하는 것이다. 즉 kubectl에서 dry run 옵션을 사용하면 일종의 연습, 테스트가 진행되는 것이다.

 

공식 문서의 코멘트는 아래와 같다.

You can use the --dry-run=client flag to preview the object that would be sent to your cluster, without really submitting it.

 

즉, --dry-run=client 플래그를 사용하면 실제로 실행하는거 없이 클러스터에 객체들이 어떻게 생상되는지 미리 볼 수 있다는 말이다.

객체는 여러가지 파일 문서로 저장되는데 나는 yaml 파일이 작성되는것을 보고 싶어서 yaml로 항상 사용한다.

(json도 있는거 같다.)

 

 

옵션을 더 디테일하게 작성하면

  • --dry-run=none
    • none옵션은 아예 사용을 안하는것과 같다. 즉, 모의테스트가 아니라 그냥 생긴다.
  • --dry-run=client
    • run을 실행하게 되면 control plan 컴포넌트인 kube-apiserver로 통신이되지만, client로 하게된다면 서버로의 통신을 하지 않고 생성만된다. 즉, 통신을 하지 않기 때문에 유효성검사나 그런 것들을 하지 않는다.
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
run: nginx
name: nginx
spec:
containers:
- image: nginx
name: nginx
resources: {}
dnsPolicy: ClusterFirst
restartPolicy: Always
status: {}
  • --dry-run=server
    • client옵션과 다르게 apiserver와 통신을 통해 유효성 검사를 한다. 실제환경과 같다.
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: "2024-02-25T06:46:28Z"
labels:
run: nginx
name: nginx
namespace: default
uid: c796e501-8cba-4093-8ed3-69ff6474f2a1
spec:
containers:
- image: nginx
imagePullPolicy: Always
name: nginx
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
name: kube-api-access-pbnjw
readOnly: true
dnsPolicy: ClusterFirst
enableServiceLinks: true
preemptionPolicy: PreemptLowerPriority
priority: 0
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
serviceAccount: default
serviceAccountName: default
terminationGracePeriodSeconds: 30
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-pbnjw
projected:
defaultMode: 420
sources:
- serviceAccountToken:
expirationSeconds: 3607
path: token
- configMap:
items:
- key: ca.crt
path: ca.crt
name: kube-root-ca.crt
- downwardAPI:
items:
- fieldRef:
apiVersion: v1
fieldPath: metadata.namespace
path: namespace
status:
phase: Pending
qosClass: BestEffort

 

client랑 server랑 헷갈릴 수도 있겠지만, 유효성검사를 하냐 안하냐는건지로 구분하는 것이라고 생각하는게 더 이해하기 쉬울것 같다는 생각이 든다. 그 외에 더 추가적인 기능이 있겠지만!

https://kubectl.docs.kubernetes.io/references/kubectl/run/

 

run

Using run command

kubectl.docs.kubernetes.io

 

반응형

'Infra Architecture > Kubernetes' 카테고리의 다른 글

[K8S] Workload - Pods  (0) 2024.02.26
[K8S TroubleShooting] no such host  (0) 2024.02.24
[K8S] Control Plane(Master Node), Worker Node  (0) 2024.02.23
[K8S] Kubernetes(쿠버네티스)  (0) 2023.09.27