Published on

Kubectl Cheatsheet

Authors
  • avatar
    Name
    Galuh Pradipta
    Twitter

If you work with Kubernetes, you know how complicated it can be to manage your Kubernetes clusters. Luckily, kubectl can help with that. Kubectl is the command-line tool for managing Kubernetes clusters. In this article, we will provide you with a kubectl cheatsheet with examples to help make your work with Kubernetes easier.

Installation

Before using kubectl, you need to install it. You can install it using the following command:

MacOS Intel

$ curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/amd64/kubectl"

MacOS ARM ( Apple Silicon)

$ curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/arm64/kubectl"

Linux

$ curl -LO "https://dl.k8s.io/release/**$(**curl -L -s https://dl.k8s.io/release/stable.txt**)**/bin/linux/amd64/kubectl"

Basic Commands

Here are the basic commands you will need to know to get started with kubectl:

  • kubectl get pods: List all the pods in the default namespace.
  • kubectl get nodes: List all the nodes in the cluster.
  • kubectl get services: List all the services in the default namespace.
  • kubectl get deployments: List all the deployments in the default namespace.
  • kubectl describe pod {pod-name}: Get detailed information about a specific pod.
  • kubectl logs {pod-name}: Get the logs for a specific pod.

Creating Resources

To create resources in your Kubernetes cluster, you can use the following commands:

  • kubectl create deployment {deployment-name} --image={image-name}: Create a new deployment using the specified image.
  • kubectl create service clusterip {service-name} --tcp={port}:{target-port}: Create a new service with a ClusterIP.
  • kubectl create configmap {configmap-name} --from-literal={key}={value}: Create a new configmap from a literal value.
  • kubectl create secret generic {secret-name} --from-literal={key}={value}: Create a new secret from a literal value.

Updating Resources

To update resources in your Kubernetes cluster, you can use the following commands:

  • kubectl set image deployment/{deployment-name} {container-name}={image-name}:{tag}: Update the image of a container in a deployment.
  • kubectl edit deployment {deployment-name}: Edit the deployment configuration in your default editor.
  • kubectl apply -f {filename}: Apply the configuration in the specified file.

Deleting Resources

To delete resources in your Kubernetes cluster, you can use the following commands:

  • kubectl delete pod {pod-name}: Delete a specific pod.
  • kubectl delete deployment {deployment-name}: Delete a specific deployment.
  • kubectl delete service {service-name}: Delete a specific service.
  • kubectl delete configmap {configmap-name}: Delete a specific configmap.
  • kubectl delete secret {secret-name}: Delete a specific secret.

Conclusion

Kubectl is a powerful tool that can help you manage your Kubernetes clusters. With this kubectl cheatsheet, you have the basic commands you need to get started with kubectl. Keep this cheatsheet handy and refer to it often to make your work with Kubernetes easier.

Further Reading

Kubectl is a powerful tool with many advanced features. If you want to learn more, here are some resources to help you get started:

Additional Notes

Kubectl is constantly evolving, and it's important to stay up-to-date with the latest updates and features. You can find the latest version of kubectl on the Kubernetes releases page. If you are using kubectl on a regular basis, it's a good idea to check for updates regularly to ensure that you have the latest features and bug fixes.

Finally, if you have any questions or issues with kubectl, there are many resources available to help you. The Kubernetes community is very active, and you can find help and support on the Kubernetes Slack channel, the Kubernetes forums, or the Kubernetes GitHub repository.You are correct, there is an error in the installation command provided. Please use this command