debug
refer
refer2

  • -v6
    kubectl scale deployment AA --replicas=6 -v 6
    
  • config
kubectl config view

# get the password for the e2e user
kubectl config view -o jsonpath='{.users[?(@.name == "e2e")].user.password}'

kubectl config view -o jsonpath='{.users[].name}'    # display the first user
kubectl config view -o jsonpath='{.users[*].name}'   # get a list of users
kubectl config get-contexts                          # display list of contexts 
kubectl config current-context                       # display the current-context
kubectl config use-context my-cluster-name           # set the default context to my-cluster-name
kubectl config unset users.foo                       # delete user foo
  • apply
    //oneline
    # Create a secret with several keys
    cat <<EOF | kubectl apply -f -
    apiVersion: v1
    kind: Secret
    metadata:
    name: mysecret
    type: Opaque
    data:
    password: $(echo -n "s33msi4" | base64 -w0)
    username: $(echo -n "jane" | base64 -w0)
    EOF
    
  • finding resources
    # List pods Sorted by Restart Count
    kubectl get pods --sort-by='.status.containerStatuses[0].restartCount'
    # Get all worker nodes (use a selector to exclude results that have a label
    # named 'node-role.kubernetes.io/master')
    kubectl get node --selector='!node-role.kubernetes.io/master'
    # Get ExternalIPs of all nodes
    kubectl get nodes -o jsonpath='{.items[*].status.addresses[?(@.type=="ExternalIP")].address}'
    # Get by Age
    kubectl get nodes --sort-by=".metadata.creationTimestamp"
    
  • updating resources
    kubectl set image deployment/frontend www=image:v2               # Rolling update "www" containers of "frontend" deployment, updating the image
    kubectl rollout history deployment/frontend                      # Check the history of deployments including the revision 
    kubectl rollout undo deployment/frontend                         # Rollback to the previous deployment
    kubectl rollout undo deployment/frontend --to-revision=2         # Rollback to a specific revision
    kubectl rollout status -w deployment/frontend                    # Watch rolling update status of "frontend" deployment until completion
    kubectl rollout restart deployment/frontend                      # Rolling restart of the "frontend" deployment
    kubectl expose rc nginx --port=80 --target-port=8000
    
  • patching resources
    # Partially update a node
    kubectl patch node k8s-node-1 -p '{"spec":{"unschedulable":true}}'
    
  • scaling
    kubectl scale --current-replicas=2 --replicas=3 deployment/mysql  # If the deployment named mysql's current size is 2, scale mysql to 3
    kubectl scale --replicas=5 rc/foo rc/bar rc/baz                   # Scale multiple replication controllers
    
  • interacting
    kubectl logs -f -l name=myLabel --all-containers    # stream all pods logs with label name=myLabel (stdout)
    kubectl run -i --tty busybox --image=busybox -- sh  # Run pod as interactive shel
    kubectl attach my-pod -i                            # Attach to Running Container
    kubectl port-forward my-pod 5000:6000               # Listen on port 5000 on the local machine and forward to port 6000 on my-pod
    kubectl exec my-pod -- ls /                         # Run command in existing pod (1 container case)
    kubectl exec -it $(kubectl get pod -l app=AA -o name) -- ls /
    kubectl top pod POD_NAME --containers               # Show metrics for a given pod and its containers
    
  • with nodes and cluster
    kubectl top node my-node                                              # Show metrics for a given node
    kubectl cluster-info dump                                             # Dump current cluster state to stdout
    # If a taint with that key and effect already exists, its value is replaced as specified.
    kubectl taint nodes foo dedicated=special-user:NoSchedule
    
  • resource types
    kubectl api-resources --namespaced=true      # All namespaced resources
    kubectl api-resources --namespaced=false     # All non-namespaced resources
    kubectl api-resources -o name                # All resources with simple output (only the resource name)
    kubectl api-resources -o wide                # All resources with expanded (aka "wide") output
    kubectl api-resources --verbs=list,get       # All resources that support the "list" and "get" request verbs
    kubectl api-resources --api-group=extensions # All resources in the "extensions" API group
    
  • log verbosity
     //
     --v=0	Generally useful for this to always be visible to a cluster operator.
     --v=1	A reasonable default log level if you don't want verbosity.
     --v=2	Useful steady state information about the service and important log messages that may correlate to significant changes in the system. This is the recommended default log level for most systems.
     --v=3	Extended information about changes.
     --v=4	Debug level verbosity.
     --v=5	Trace level verbosity.
     --v=6	Display requested resources.
     --v=7	Display HTTP request headers.
     --v=8	Display HTTP request contents.
     --v=9	Display HTTP request contents without truncation of contents.
    
  • raw api
    kubectl get --raw /api/v1/nodes/<node>/proxy/stats/summary
    
  • kubectl delete pod
    termination lifecycle

  • kubectl apply/replace/patch
    article

  • kubectl create/apply
    vs

container

 time cat /sys/fs/cgroup/memory/memory.stat >/dev/null

etcd

etcdctl --endpoints 127.0.0.1:2379,127.0.0.1:2380,127.0.0.1:2381 endpoint status --cluster -w table
etcdctl defrag —command-timeout=5m
ETCDCTL_API=3 etcdctl move-leader ${MEMBER_ID} --endpoints http://etcd-0.etcd:2380,http://etcd-1.etcd:2380,http://etcd-2.etcd:2380

iptables

sudo iptables -L KUBE-NODEPORTS -t nat
sudo iptables -L KUBE-MARK-MASQ -t nat

bash alias

kall() { kubectl get pods --all-namespaces -o wide --field-selector spec.nodeName="$1"; }