1. Nodes
| Commands | Description |
|---|
| kubectl get node | To list down all worker nodes. |
| kubectl delete node <node_name> | Delete the given node in cluster. |
| kubectl top node | Show metrics for a given node. |
| kubectl describe nodes | grep ALLOCATED -A 5 | Describe all the nodes in verbose. |
| kubectl get pods -o wide | grep <node_name> | List all pods in the current namespace, with more details. |
| kubectl get no -o wide | List all the nodes with mode details. |
| kubectl describe no | Describe the given node in verbose. |
| kubectl annotate node <node_name> | Add an annotation for the given node. |
| kubectl uncordon node <node_name> | Mark my-node as schedulable. |
| kubectl label node | Add a label to given node |
2. Pods
| Commands | Description |
|---|
| kubectl get po | To list the available pods in the default namespace. |
|---|
| kubectl describe pod <pod_name> | To list the detailed description of pod. |
|---|
| kubectl delete pod <pod_name> | To delete a pod with the name. |
|---|
| kubectl create pod <pod_name> | To create a pod with the name. |
|---|
| Kubectl get pod -n <name_space> | To list all the pods in a namespace. |
|---|
| Kubectl create pod <pod_name> -n <name_space> | To create a pod with the name in a namespace. |
|---|
3. Namespaces
| Commands | Description |
|---|
| kubectl create namespace <namespace_name> | To create a namespace by the given name. |
|---|
| kubectl get namespace | To list the current namespace in a cluster. |
|---|
| kubectl describe namespace <namespace_name> | To display the detailed state of one or more namespaces. |
|---|
| kubectl delete namespace <namespace_name> | To delete a namespace. |
|---|
| kubectl edit namespace <namespace_name> | To edit and update the definition of a namespace. |
|---|
4. Services
| Commands | Description |
|---|
| kubectl get services | To list one or more services. |
|---|
| kubectl describe services <services_name> | To list the detailed display of services. |
|---|
| kubectl delete services -o wide | To delete all the services. |
|---|
| kubectl delete service < service_name> | To delete a particular service. |
|---|
5. Deployments
| Commands | Description |
|---|
| kubectl create deployment <deployment_name> | To create a new deployment. |
|---|
| kubectl get deployment | To list one or more deployments. |
|---|
| kubectl describe deployment <deployment_name> | To list a detailed state of one or more deployments. |
|---|
| kubectl delete deployment<deployment_name> | To delete a deployment. |
|---|
6. DaemonSets| Command | Description |
|---|
| kubectl get ds | To list out all the daemon sets. |
|---|
| kubectl get ds -all-namespaces | To list out the daemon sets in a namespace. |
|---|
| kubectl describe ds [daemonset_name][namespace_name] | To list out the detailed information for a daemon set inside a namespace. |
|---|
7. Events| Commands | Description |
|---|
| kubectl get events | To list down the recent events for all the resources in the system. |
|---|
| kubectl get events --field-selector involvedObject.kind != Pod | To list down all the events except the pod events. |
|---|
| kubectl get events --field-selector type != Normal | To filter out normal events from a list of events. |
|---|
8. Logs
| Commands | Description |
|---|
| kubectl logs <pod_name> | To display the logs for a Pod with the given name. |
|---|
| kubectl logs --since=1h <pod_name> | To display the logs of last 1 hour for the pod with the given name. |
|---|
| kubectl logs --tail-20 <pod_name> | To display the most recent 20 lines of logs. |
|---|
| kubectl logs -c <container_name> <pod_name> | To display the logs for a container in a pod with the given names. |
|---|
| kubectl logs <pod_name> pod.log | To save the logs into a file named as pod.log. |
|---|
9. ReplicaSets
| Commands | Description |
|---|
| kubectl get replicasets | To List down the ReplicaSets. |
|---|
| kubectl describe replicasets <replicaset_name> | To list down the detailed state of one or more ReplicaSets. |
|---|
| kubectl scale --replace=[x] | To scale a replica set. |
|---|
10. Service Accounts
| Commands | Description |
|---|
| kubectl get serviceaccounts | To List Service Accounts. |
|---|
| kubectl describe serviceaccounts | To list the detailed state of one or more service accounts. |
|---|
| kubectl replace serviceaccounts | To replace a service account. |
|---|
| kubectl delete serviceaccounts <name> | To delete a service account. |
|---|
Changing Resource Attributes
Taints: They ensure that pods are not placed on inappropriate nodes.
| Command | Description |
|---|
| kubectl taint <node_name><taint_name> | This is used to update the taints on one or more nodes. |
|---|
Labels: They are used to identify pods.
| Command | Description |
|---|
| kubectl label pod <pod_name> | Add or update the label of a pod |
|---|
For Cluster Introspection| Commands | Description |
|---|
| kubectl version | To get the information related to the version. |
|---|
| kubectl cluster-info | To get the information related to the cluster. |
|---|
| kubectl config g view | To get the configuration details. |
|---|
| kubectl describe node <node_name> | To get the information about a node. |
|---|
Interacting with Deployments and Services| Commands | Description |
|---|
| kubectl logs deploy/my-deployment | Dump Pod logs for a Deployment (single-container case). |
|---|
| kubectl logs deploy/my-deployment -c my-contain | dump Pod logs for a Deployment (multi-container case). |
|---|
| kubectl port-forward svc/my-service 5000 | To listen on local port 5000 and forward to port 5000 on Service backend. |
|---|
| kubectl port-forward deploy/my-deployment 5000:6000 | To listen on local port 5000 and forward to port 6000 on a Pod created by <my-deployment>. |
|---|
| kubectl exec deploy/my-deployment -- ls | To run command in first Pod and first container in Deployment (single- or multi-container cases). |
|---|
No comments:
Post a Comment