Term
Generate a plain-text list of all namespaces |
|
Definition
|
|
Term
Show a plain-text list of all pods: |
|
Definition
|
|
Term
Generate a detailed plain-text list of all pods, containing information such as node name: |
|
Definition
|
|
Term
Display a list of all pods running on a particular node server: |
|
Definition
kubectl get pods --field-selector=spec.nodeName=[server-name] |
|
|
Term
List a specific replication controller in plain-text: |
|
Definition
kubectl get replicationcontroller [replication-controller-name] |
|
|
Term
Generate a plain-text list of all replication controllers and services: |
|
Definition
kubectl get replicationcontroller,services |
|
|
Term
Show a plain-text list of all daemon sets: |
|
Definition
|
|
Term
Create a resource such as a service, deployment, job, or namespace using the kubectl create command.
For example, to create a new namespace, type: |
|
Definition
kubectl create namespace [namespace-name]
and
kubectl create -f [filename] |
|
|
Term
Create a new service with the definition contained in a [service-name].yaml file: |
|
Definition
kubectl apply -f [service-name].yaml |
|
|
Term
Create a new replication controller with the definition contained in a [controller-name].yaml file: |
|
Definition
kubectl apply -f [controller-name].yaml |
|
|
Term
Create the objects defined in any .yaml, .yml, or .json file in a directory: |
|
Definition
kubectl apply -f [directory-name] |
|
|
Term
You can update a resource by configuring it in a text editor, using the kubectl edit command. This command is a combination of kubectl get and kubectl apply .
For example, to edit a service, type: |
|
Definition
kubectl edit svc/[service-name] |
|
|
Term
This command opens the file in your default editor. To use a different editor, specify it in front of the command: |
|
Definition
KUBE_EDITOR=”[editor-name]” kubectl edit svc/[service-name] |
|
|
Term
To display the state of any number of resources in detail, use the kubectl describe command. By default, the output also lists uninitialized resources.
View details about a particular node: |
|
Definition
kubectl describe nodes [node-name] |
|
|
Term
View details about a particular pod: |
|
Definition
kubectl describe pods [pod-name] |
|
|
Term
Display details about a pod whose name and type are listed in pod.json: |
|
Definition
kubectl describe -f pod.json |
|
|
Term
See details about all pods managed by a specific replication controller: |
|
Definition
kubectl describe pods [replication-controller-name] |
|
|
Term
Show details about all pods: |
|
Definition
|
|
Term
To remove resources from a file or stdin, use the kubectl delete command.
Remove a pod using the name and type listed in pod.yaml: |
|
Definition
kubectl delete -f pod.yaml |
|
|
Term
Remove all pods and services with a specific label: |
|
Definition
kubectl delete pods,services -l [label-key]=[label-value] |
|
|
Term
Remove all pods (including uninitialized pods): |
|
Definition
kubectl delete pods --all |
|
|
Term
Use kubectl exec to issue commands in a container or to open a shell in a container.
Receive output from a command run on the first container in a pod: |
|
Definition
kubectl exec [pod-name] -- [command] |
|
|
Term
Run /bin/bash from a specific pod. The received output comes from the first container: |
|
Definition
kubectl exec -ti [pod-name] -- /bin/bash |
|
|
Term
Listing resources- for listing pods, services, replication controllers, or daemon sets, you can use this command:
|
|
Definition
|
|
Term
- Create a plain list of all namespaces:
|
|
Definition
|
|
Term
|
Definition
|
|
Term
- Create a detailed list of pods which must consist of information like node name:
|
|
Definition
|
|
Term
- Create a list of pods running on a specific node server:
|
|
Definition
kubectl get pods --field-selector=spec.nodeName=[server-name] |
|
|
Term
- List a replication controller:
|
|
Definition
kubectl get replicationcontroller [replication-controller-name] |
|
|
Term
- Create a list of services and replication controllers together:
|
|
Definition
kubectl get replicationcontroller,services |
|
|
Term
Here is how you can troubleshoot Kubernetes using Kubectl: |
|
Definition
|
|
Term
It shows the details of the resource you are currently viewing. It’s mostly used to describe a pod or node and check for any errors in the events or if the resources are limited. Resources that can be described are – nodes, pods, deployments, services, replica sets, and Cronjobs.
The following is an example showing how to describe the cronjob in a cluster: |
|
Definition
kubectl describe cronjob my-cron |
|
|
Term
Kubectl logs
The kubectl describe command provides the events that occur in the applications inside a pod, whereas kubectl logs offer detailed insights into Kubernetes. Understanding this difference will allow you to fix issues that occur in the Kubernetes as well as in applications too. |
|
Definition
$ kubectl logs cherry-chart-88d49478c-dmcfv -n charts |
|
|
Term
Kubectl exec
You can also execute a container just like the docker exec command for troubleshooting an application directly. This command proves to be useful when the logs don’t fix the problems that may be arising. While using the exec command, the end of the line must provide the shell you intend to use in the pod. |
|
Definition
kubectl exec -it cherry-chart-88d49478c-dmcfv -n charts -- /bin/bash
root@cherry-chart-88d49478c-dmcfv:/# |
|
|
Term
Kubectl cp
If you wish to copy directories and files to and from containers, this command is a must, just like the Linux cp command. This command is essential for restoring backups when automation fails.
Here’s the syntax to copy a file to the container: |
|
Definition
kubectl cp <filename> <namespace/podname:/path/tofile> format |
|
|
Term
The syntax for pulling a file to the local machine from a container: |
|
Definition
kubectl cp <namespace/podname:/path/tofile> |
|
|
Term
You can also change the default grace period when you manually delete a resource with kubectl delete command, adding the parameter |
|
Definition
kubectl delete deployment test --grace-period=60 |
|
|
Term
Cluster Management
Display endpoint information regarding the services and master in the cluster |
|
Definition
|
|
Term
Show the Kubernetes version functioning on the client and server |
|
Definition
|
|
Term
Get the configuration of the cluster |
|
Definition
|
|
Term
Make a list of the available API resources |
|
Definition
|
|
Term
Make a list of the available API versions |
|
Definition
|
|
Term
|
Definition
kubectl get all –all-namespaces |
|
|
Term
2. Namespaces
Create namespace <name> |
|
Definition
kubectl create namespace <namespace_name> |
|
|
Term
List one or more namespaces |
|
Definition
kubectl get namespace <namespace_name> |
|
|
Term
Show the detailed condition of one or more namespace |
|
Definition
kubectl describe namespace <namespace_name> |
|
|
Term
kubectl delete namespace <namespace_name> |
|
Definition
|
|
Term
Edit and modify the namespace’s definition |
|
Definition
kubectl edit namespace <namespace_name> |
|
|
Term
Display Resource (CPU/Memory/Storage) usage for a namespace |
|
Definition
kubectl top namespace <namespace_name> |
|
|
Term
Node operations
A Node is a worker machine in Kubernetes and can either be a virtual or a physical machine, which depends on the cluster. Every Node is handled by the control plane. A Node can contain several pods, and the Kubernetes control plane handles scheduling the pods automatically across the Nodes in the cluster. Following commands can be utilised for Node Operation
Revise the taints on one or more nodes |
|
Definition
kubectl taint node <node_name> |
|
|
Term
|
Definition
|
|
Term
Delete a node or multiple nodes |
|
Definition
kubectl delete node <node_name> |
|
|
Term
Display Resource usage (CPU/Memory/Storage) for nodes |
|
Definition
|
|
Term
Resource allocation per node |
|
Definition
kubectl describe nodes | grep Allocated -A 5 |
|
|
Term
|
Definition
kubectl get pods -o wide | grep <node_name> |
|
|
Term
|
Definition
kubectl annotate node <node_name> |
|
|
Term
Mark a node as unschedulable |
|
Definition
kubectl cordon node <node_name> |
|
|
Term
|
Definition
kubectl uncordon node <node_name> |
|
|
Term
Drain a node in preparation for maintenance |
|
Definition
kubectl drain node <node_name> |
|
|
Term
Add the labels of one or more nodes |
|
Definition
|
|
Term
Listing Resources
Kubernets resources also regarded as Kubernetes objects related to a certain namespace, you can either utilise individual kubectl get command to jot down every resource one by one, or you can jot down all the resources in a Kubernetes namespace by executing a single command. Mentioned below are the list of commands to get the resources information.
Create a plain-text list of all namespaces |
|
Definition
|
|
Term
Create a plain-text list of all pods |
|
Definition
|
|
Term
Create a comprehensive plain-text list of all pods |
|
Definition
|
|
Term
Create a list of all pods functioning on a certain node server |
|
Definition
kubectl get pods–field-selector=spec. nodeName=[server-name] |
|
|
Term
In plain text, make a lst a specific replication controller |
|
Definition
kubectl get replicationcontroller [replication-controller-name] |
|
|
Term
Generate a plain-text list of all replication services and controllers |
|
Definition
kubectl get replicationcontroller, services |
|
|
Term
Daemonsets
A Daemonset assures that some or all Nodes run a copy of a Pod. As nodes are incorporated to the cluster, Pods are implemented to them. As nodes are erased from the cluster, those Pods are garbage collected. Erasing a DaemonSet will clean up the Pods it created.
List one or more daemonsets
|
|
Definition
|
|
Term
Edit and modify the definition of one or more daemonset |
|
Definition
kubectl edit daemonset <daemonset_name> |
|
|
Term
|
Definition
kubectl delete daemonset <daemonset_name> |
|
|
Term
|
Definition
kubectl create daemonset <daemonset_name> |
|
|
Term
Manage the rollout of a daemonset |
|
Definition
kubectl rollout daemonset |
|
|
Term
Show the comprehensive state of daemonsets within a namespace |
|
Definition
kubectl describe ds <daemonset_name> -n <namespace_name> |
|
|
Term
Shortcode = ev Kubernetes events are objects that displays what is happening within a cluster, like what decisions were implemented by the scheduler or why some pods were erased from the node. Events are the first thing to look at for application, along with infrastructure operations when something is not functioning as anticipated. Mentioned below are the kubectl commands to get the events.
List current events for all resources in the system |
|
Definition
|
|
Term
|
Definition
kubectl get events –field-selector type=Warning |
|
|
Term
List events but exclude Pod events |
|
Definition
kubectl get events –field-selector involvedObject.kind!=Pod |
|
|
Term
Pull events for a single node with a distinct name |
|
Definition
kubectl get events –field-selector involvedObject.kind=Node, involvedObject.name=<node_name> |
|
|
Term
From a list of events, filter out normal events |
|
Definition
kubectl get events –field-selector type!=Normal |
|
|
Term
7. Logs
You can use Kubernets logs commands to monitor, log and debug the pods
Print the logs for a pod
|
|
Definition
|
|
Term
Print the logs for a pod for the last hour |
|
Definition
kubectl logs –since=1h <pod_name> |
|
|
Term
Get the current 20 lines of logs |
|
Definition
kubectl logs –tail=20 <pod_name> |
|
|
Term
Get logs from a service and choose which container optionally |
|
Definition
kubectl logs -f <service_name> [-c <$container>] |
|
|
Term
Adhere to new logs and print the logs for a pod |
|
Definition
kubectl logs -f <pod_name> |
|
|
Term
For a container in a pod, Print the logs |
|
Definition
kubectl logs -c <container_name> <pod_name> |
|
|
Term
Output the logs for a pod into a ‘pod.log’ file |
|
Definition
kubectl logs <pod_name> pod.log |
|
|
Term
View the logs for the last failed pod |
|
Definition
kubectl logs –previous <pod_name> |
|
|
Term
Shortcode = deploy.
A Kubernetes Deployment is utilised to inform Kubernetes how to design or change instances of the pods that hold a containerized application. Deployments can enhance the number of replica pods, enable rollout of revised code in a controlled way, or roll back to an earlier deployment version if required.
List one or more deployments |
|
Definition
|
|
Term
Show the in-depth state of one or more deployments |
|
Definition
kubectl describe deployment <deployment_name> |
|
|
Term
Edit and revise the definition of one or more deployment on the server |
|
Definition
kubectl edit deployment <deployment_name> |
|
|
Term
Generate one a new deployment |
|
Definition
kubectl create deployment <deployment_name> |
|
|
Term
|
Definition
kubectl delete deployment <deployment_name> |
|
|
Term
Check the rollout status of a deployment |
|
Definition
kubectl rollout status deployment <deployment_name> |
|
|
Term
12. Services and Service Accounts:
A Kubernetes service is a logical abstraction for a deployed group of pods in a cluster (which all perform the same function) and Service accounts are used to provide an identity for pods. Pods that want to interact with the API server will authenticate with a particular service account.
Make a list of one or more services |
|
Definition
|
|
Term
Show the detailed state of a service |
|
Definition
kubectl describe services |
|
|
Term
Reveal a replication controller, service, deployment or pod as a new Kubernetes service |
|
Definition
- kubectl expose deployment [deployment_name]
|
|
|
Term
Edit and modify the definition of one or more services |
|
Definition
|
|
Term
|
Definition
kubectl get serviceaccounts |
|
|
Term
Show the in-depth state of one or more service accounts |
|
Definition
kubectl describe serviceaccounts |
|
|
Term
Replace a service account |
|
Definition
kubectl replace serviceaccount |
|
|
Term
|
Definition
kubectl delete serviceaccount <service_account_name> |
|
|