ex) kubectl describe pod/weave-net-2hn7s -n kube-system
List all pods with labels kubectl get pods --show-labels
List running pods kubectl get pods --field-selector=status.phase=Running --all-namespaces
Watch pods kubectl get pods -n --watch
List pods and containers kubectl get pods --all-namespaces -o='custom-columns=PODS:.metadata.name,CONTAINERS:.spec.containers[*].name'
List pods, containers and images kubectl get pods --all-namespaces -o='custom-columns=PODS:.metadata.name,CONTAINERS:.spec.containers[*].name,Images:.spec.containers[*].image'
Scale out Deployment kubectl scale --replicas=3 ds
특정 namespace pods상세 보기
kubectl describe pods -n audacity
예) eksctl delete cluster --name eksctl-demo
kubectl expose deployment canary-v1 -n udacity
특정 service를 yaml로 확인하기 kubectl get service <> -n <> -o yaml
kubectl get service canary-v1 -n udacity -o yaml
ex)
export KUBECONFIG="C:\Users\home\.kube\config"
kubectl config view
Switch context kubectl config use-context
Delete the specified context kubectl config delete-context
List all namespaces defined kubectl get namespaces
namespace 생성 kubectl create namespace <<namespace_name>>
예)kubectl create namespace monitoring
기본 namespace 변경하기 kubectl config set-context --current --namespace=<>
kubectl config set-context --current --namespace=udacity
List certificates kubectl get csr --all-namespaces
aws IAM User 변경 kubectl edit configmap aws-auth -n kube-system
cofigmap 조회 kubectl get configmap -n udacity
configmap 상세 조회 kubectl describe configmap/canary-config-v1 -n udacity
kubectl exec --stdin --tty hello-8445fd55cb-s9bps -- /bin/sh
Check pod environment variables kubectl exec -n env
Get pods sorted by restart count kubectl get pods --sort-by='.status.containerStatuses[0].restartCount' --all-namespaces
List all container images kubectl get pods –all-namespaces -o jsonpath=“{..image}” | tr -s ‘[[:space:]]’ ‘\n’ | sort | uniq -d
kubectl describe serviceaccount ops-view -n udacity
clusterrolebinding 만들기
(role과 service account 연결)
https://kubernetes.io/docs/reference/access-authn-authz/rbac/#user-facing-roles kubectl create clusterrolebinding <> --clusterrole=<> --serviceaccount <> -n <
kubectl create clusterrolebinding ops-view-binding --clusterrole=cluster-admin --serviceaccount udacity:ops-view -n udacity
clusterrolebinding 상세 보기 kubectl describe clusterrolebinding <>
kubectl describe clusterrolebinding ops-view-binding
role binding된 service account를 특정 pod에 붙이기 위해서는 yml spec이하에 serviceAccountName을 기입하고 재 apply 해야함
apiVersion: apps/v1
kind: Deployment
metadata:
name: ops-view
namespace: udacity
spec:
replicas: 1
selector:
matchLabels:
app: ops-view
template:
metadata:
labels:
app: ops-view
spec:
serviceAccountName: ops-view
containers:
kubectl set image deployment nginx-rolling nginx=nginx:1.21.1 --record -n udacity
rollout 상태 확인하기 kubectl rollout status deployment/<> -n <>
kubectl rollout status deployment/nginx-rolling -n udacity
rollout 일시정지 시키기 kubectl rollout pause deployment/<> -n <>
kubectl rollout pause deployment/nginx-rolling -n udacity
rollout 재실행 kubectl rollout resume deployment/nginx-rolling -n udacity
rollout 취소 kubectl rollout undo deployment/nginx-rolling -n udacity
rollout 기록 보기 kubectl rollout history deployment/nginx-rolling -n udacity
예)kubectl delete secrets additional-scrape-configs -n monitoring
secret 추가하기 kubectl create secret generic <> --from-file=<<file명>> --namespace <>
예) kubectl create secret generic additional-scrape-configs --from-file=prometheus-additional.yaml --namespace monitoring
예) helm install prometheus-blackbox-exporter prometheus-community/prometheus-blackbox-exporter -f "blackbox_values.yaml" --namespace monitoring
예)aws eks update-kubeconfig --region us-east-2 --name udacity-cluster