Skip to main content

Command Table

In this section, we'll cover some essential K8s commands that are useful for managing applications. These commands will help you apply and edit manifests, check the status of resources, inspect pods, retrieve logs, and delete resources.

1. Apply and Edit Manifests

Applying Manifests To deploy applications or configure resources in Kubernetes, you use manifests, which are YAML or JSON files that describe your desired resources. To apply a manifest file, use the following command:

kubectl apply -f <spec.yaml>

This command creates or updates resources in your cluster based on the specifications in <filename.yaml>.

Editing Manifests If you need to make changes to a resource directly from the command line, you can use:

kubectl edit <resource-type> <resource-name>

This command opens the resource’s manifest in your default text editor, allowing you to make live edits. For example, to edit a deployment named my-deployment, you would use:

kubectl edit deployment my-deployment

2. Status Commands

Checking the Status of Pods To view all pods, use:

kubectl get pods -n <namespace>

To pods with more informationl, use:

kubectl get pods -o wide

Viewing Deployments To get an overview of all deployments, use:

kubectl get deployments

Or in a specific deployment

kubectl get deployment <deployment_name>

Viewing Services To get an overview of all services in the current namespace, use:

kubectl get services

3. Describe Pods and Get Logs

Describing Pods To get more detailed information about a specific pod, use:

kubectl describe pod <pod-name>

This provides detailed information about the pod’s configuration and status, including events related to the pod.

Getting Logs from a Pod To retrieve the logs of a specific pod, which is crucial for debugging, use:

kubectl logs <pod-name>

If the pod contains more than one container, specify the container:

kubectl logs <pod-name> -c <container-name>

4. Delete Resources

Deleting a Pod To delete a specific pod:

kubectl delete pod <pod-name>

This command removes the pod from your cluster. Be careful with this command, as it will not ask for confirmation by default.

Deleting Other Resources Similarly, to delete any other Kubernetes resource, such as a deployment, or service:

kubectl delete <resource-type> <resource-name>

To delete a deployment, use:

kubectl delete deployment <deployment_name>