[k8s] 유용한 명령어 (정리중) By starseat 2022-05-31 18:05:23 server/oss Post Tags #### GET ``` // default namespace의 pod조회 kubectl get pods // 모든 namespace의 pod조회 kubectl get pods --all-namespaces // node 조회 kubectl get node // 특정 namespace의 pod 조회 kubectl get pods -n {node 명} // pod 정보 자세히 보기 kubectl get pod -o wide // pod watch mode로 보기 kubectl get pod -w // default namespace의 deployment조회 kubectl get deploy // 모든 namespace의 모든 deployment조회 kubectl get deploy --all-namespaces // default namespace의 service조회 kubectl get service kubectl get svc // 모든 namespace의 모든 service조회 kubectl get service --all-namespaces ``` ##### pod 내부 접속 ``` kubectl exec {pod 명} /bin/bash --stdin --tty -n {namespace} kubectl exec -it app -- cat /log/app.log -n elastic-stack kubectl exec {pod} -it /bin/bash -n {namespace} ``` ##### 로그 보기 ``` // 특정 pod 로그 확인 kubectl get pods kubectl logs {pod 명} // 특정 pod 로그 확인 (tail) kubectl logs -f {pod 명} ``` ``` kubectl logs {pod 명} -c {container 명} -n {name-space} --follow // ex > k get po -n web-dev NAME READY STATUS RESTARTS AGE api-auth-84fc4d6fbc-74cgr 2/2 Running 1 22d > k logs api-auth-84fc4d6fbc-74cgr -c api-auth -n web-dev --follow ``` ##### ClusterIP 접근 ``` {ServiceName}.{NameSpace}.svc.cluster.local ``` ##### pod 강제 삭제 ``` // kubectl version >= 1.5 kubectl delete pods {pod 명} --grace-period=0 --force // kubectl version <= 1.4 --force 옵션 제거 kubectl delete pods {pod 명} --grace-period=0 // ex > k get po -n web-dev NAME READY STATUS RESTARTS AGE api-auth-84fc4d6fbc-74cgr 2/2 Running 1 22d > k delete pods api-auth-84fc4d6fbc-74cgr -n web-dev --grace-period=0 --force ``` ##### yaml 추출 ``` kubectl run webserver --image={image 명} {--port 80} --dry-run -o yaml > {file name}.yaml ``` #### context ``` // context 조회 > kubectl config get-contexts // 현재 context 조회 > kubectl config current-context // context 변경 // kubectl config use-context {context 명} > kubectl config use-context hk8s ``` ##### short 확인 ``` > k api-resources NAME SHORTNAMES APIVERSION NAMESPACED KIND bindings v1 true Binding componentstatuses cs v1 false ComponentStatus configmaps cm v1 true ConfigMap endpoints ep v1 true Endpoints events ev v1 true Event limitranges limits v1 true LimitRange namespaces ns v1 false Namespace nodes no v1 false Node persistentvolumeclaims pvc v1 true PersistentVolumeClaim persistentvolumes pv v1 false PersistentVolume pods po v1 true Pod podtemplates v1 true PodTemplate replicationcontrollers rc v1 true ReplicationController resourcequotas quota v1 true ResourceQuota secrets v1 true Secret serviceaccounts sa v1 true ServiceAccount services svc v1 true Service mutatingwebhookconfigurations admissionregistration.k8s.io/v1 false MutatingWebhookConfiguration validatingwebhookconfigurations admissionregistration.k8s.io/v1 false ValidatingWebhookConfiguration customresourcedefinitions crd,crds apiextensions.k8s.io/v1 false CustomResourceDefinition apiservices apiregistration.k8s.io/v1 false APIService controllerrevisions apps/v1 true ControllerRevision daemonsets ds apps/v1 true DaemonSet deployments deploy apps/v1 true Deployment replicasets rs apps/v1 true ReplicaSet statefulsets sts apps/v1 true StatefulSet tokenreviews authentication.k8s.io/v1 false TokenReview localsubjectaccessreviews authorization.k8s.io/v1 true LocalSubjectAccessReview selfsubjectaccessreviews authorization.k8s.io/v1 false SelfSubjectAccessReview selfsubjectrulesreviews authorization.k8s.io/v1 false SelfSubjectRulesReview subjectaccessreviews authorization.k8s.io/v1 false SubjectAccessReview horizontalpodautoscalers hpa autoscaling/v2 true HorizontalPodAutoscaler cronjobs cj batch/v1 true CronJob jobs batch/v1 true Job certificatesigningrequests csr certificates.k8s.io/v1 false CertificateSigningRequest leases coordination.k8s.io/v1 true Lease endpointslices discovery.k8s.io/v1 true EndpointSlice events ev events.k8s.io/v1 true Event flowschemas flowcontrol.apiserver.k8s.io/v1beta2 false FlowSchema prioritylevelconfigurations flowcontrol.apiserver.k8s.io/v1beta2 false PriorityLevelConfiguration ingressclasses networking.k8s.io/v1 false IngressClass ingresses ing networking.k8s.io/v1 true Ingress networkpolicies netpol networking.k8s.io/v1 true NetworkPolicy runtimeclasses node.k8s.io/v1 false RuntimeClass poddisruptionbudgets pdb policy/v1 true PodDisruptionBudget podsecuritypolicies psp policy/v1beta1 false PodSecurityPolicy clusterrolebindings rbac.authorization.k8s.io/v1 false ClusterRoleBinding clusterroles rbac.authorization.k8s.io/v1 false ClusterRole rolebindings rbac.authorization.k8s.io/v1 true RoleBinding roles rbac.authorization.k8s.io/v1 true Role priorityclasses pc scheduling.k8s.io/v1 false PriorityClass csidrivers storage.k8s.io/v1 false CSIDriver csinodes storage.k8s.io/v1 false CSINode csistoragecapacities storage.k8s.io/v1beta1 true CSIStorageCapacity storageclasses sc storage.k8s.io/v1 false StorageClass volumeattachments storage.k8s.io/v1 false VolumeAttachment ``` Previous Post [redis] MISCONF Redis is configured to save RDB snapshot... 오류 Next Post [k8s] ingress 설정