kubectl-cheat-sheet-it
kubectl-cheat-sheet-it
🔥 kubectl cheat sheet (2022 trainer) VSFW!
1 post
The Ultimate Kubectl Commands Cheat Sheet. 
Don't wanna be here? Send us removal request.
kubectl-cheat-sheet-it · 3 years ago
Text
kubectl cheat sheet free VSFW!
💾 ►►► DOWNLOAD FILE 🔥🔥🔥🔥🔥 List all namespace services · 2. Retrieve details on your nodes · 3. Create a new namespace with a unique name · 4. Leverage your files to configure Kubernetes. Kubectl is the command line configuration tool for Kubernetes. Our kubectl cheatsheet provides an overview of the most useful commands for K8s objects. Kubectl is the standard command line used to communicate with Kubernetes, this article is an The Ultimate Kubectl Commands Cheat Sheet. k8s kubectl cheat sheet. GitHub Gist: instantly share code, notes, and snippets. 9 If you are reading this article, you are probably familiar with Kubernetes and want to interact with a Kubernetes cluster. Regardless of the way you have provisioned the cluster, kubectl is the standard command line used to communicate with it. This article assumes that you have a basic knowledge of Kubernetes and the kubectl command. The --prune option for the kubectl apply command allows you to achieve a completely declarative approach, but this option is currently in alpha at the time of this writing and thus not considered suitable for general use. Before diving into the code, it is important to note a few things. The object notation is usually in the form of object type, followed by a slash, followed by the object name. Some commands accept different notations e. This is the TL;DR section of this article—a quick-access section to remind you of the most important commands. No explanations are given, but the commands are explained further down in the article. Komodor monitors your entire K8s stack, identifies issues, and uncovers their root cause. Get Started Free. Contexts are stored in a kubeconfig file, which can store multiple contexts. Contexts will usually be provided by some other commands related to the control plane or some other management commands. Such commands will usually add context to your kubeconfig file. If you have only one context i. If you are working with two or more clusters, you might want to consider using the --context command line option. The reason is that if you often switch between clusters, you are pretty much guaranteed that one day you will run a kubectl command that you intended for another cluster, and the consequences might very well be dramatic. With this in mind, you might want to set your default context to something innocuous, like minikube, and force yourself to explicitly provide the --context option on every kubectl command. Kubectl get is probably the command you will use the most, so it deserves its own section. Kubectl get can retrieve information about all Kubernetes objects, as well as nodes in the Kubernetes data plane. The most common Kubernetes objects you are likely to query are pods, services, deployments, stateful sets, and secrets. List all pods in the default namespace in this case, there are no pods in the default namespace :. The NODE column shows on which node the pod is running or is scheduled. The kubernetes service is used to access the Kubernetes API from within the cluster and is usually located in the default namespace. Kubernetes stores secrets as baseencoded values, hence the base64 -d at the end to show a human-readable value. The base64 command is available on many operating systems, but you might need to change for your OS. There are many other commands to retrieve information besides kubectl get. In no particular order, here is a selection of the most important:. To retrieve a lot of information about Kubernetes objects that are not shown by kubectl get, use kubectl describe :. This command provides a lot of information and is very useful to understand why a pod is having problems. It shows the detailed status of all the containers, the mounted volumes, and the events associated with the pod. In most cases, running this command is all you need to understand why your pod is not working the way you want. If the problem is still not apparent, however, you might want to run kubectl describe node , which will provide you with useful information about the Kubernetes nodes, such as the cumulative allocated resources like CPU and memory. The -c argument is used to specify which container in the pod to query; if the pod has only one container, this argument is optional. Please note that kubectl logs will show the logs from the current log file on the node that is running the pod. Such log files are subject to rotation, so kubectl logs will show only the most recent log entries. Generally speaking, you would use kubectl logs only for debugging during the development stage. For production environments, you will most likely use a log aggregator and query for the logs from there. Nevertheless, this command is one of your first ports of call to troubleshoot misbehaving pods and connectivity problems. It should be noted that in many cases, you can get the logs of system pods running in the kube-system namespace, such as the API server, the DNS server, kube-proxy pods, etc. Some clusters have been set up to run those services directly on the control node s rather than pods, so in such cases you will need to check the logs directory on the control node s. These commands directly instruct Kubernetes to perform a specific operation on a given object. This section will show the most common such commands in no particular order. These are useful during the development stages, but you should definitely avoid them in a production environment. Use kubectl create to create a Kubernetes object, except for pods that are created using the kubectl run command. So to create a pod directly:. Using the run command is good enough for running simple pods. To delete the pod:. You can directly create all other Kubernetes objects using the kubectl create command. Here is a silly example for creating a Deployment:. Please note that not all elements of a Kubernetes object can be modified after it has been created. Another method to modify a Kubernetes object is to use the patch command. With the above deployment object, such a command could look like this:. This is one example where working with manifest files and using the declarative style make things much easier. You can also use the kubectl set command to easily modify certain objects, but it is limited in scope and not generic. It is mostly used to modify the image of pods or deployments, for example:. Another way to modify objects is to add or change the labels and annotations attached to it, for example:. When you want to work in declarative mode, you will have a manifest file or a set of them , and essentially use only one command:. Here, X is a file or a directory you can add multiple -f arguments if necessary. If you want to make some changes to your existing Kubernetes objects, just modify the manifest files and run kubectl apply again. This will compute the differences between your desired state and the existing state and make the necessary changes to reconcile them. If you use kustomization files, you should use the -k option instead, and the argument must be a directory:. There is a special case where the reconciliation is problematic, which has to do with the Kubernetes authorization system. The reasons for this are quite obscure and are touched on here if you are interested. If you make changes to RBAC resources or roles, you should use the kubectl auth reconcile command. You can find more information on this in the official Kubernetes documentation. Here are some useful commands to manage deployments in a general sense, so that also includes stateful sets and daemon sets. In practice, however, these commands are seldom used because you would manage deployments using Helm or some other similar software. Again, in practice, you are likely either to use Helm to perform static, manual changes or the pod autoscaler and not perform any manual operation. BTW, you can set up some basic autoscaling using kubectl autoscale , although that works only with one metric: CPU utilization. If your Docker registry is private, you will need to pass some credentials to Kubernetes. The easiest way to do this is to first login using the Docker command line, for example, on AWS:. So, if you see that error and you are using a private registry, you might want to check that you did set imagePullSecrets , and that the secret is not expired. Nothing beats getting a shell to a running pod! Consequently, you might need to think about how such containers will be troubleshooted. You might want to have two versions of such containers: One for development with the shell and maybe other programs and one for production which would be distroless. You can quickly create a link between a given port number on a given pod running inside the Kubernetes cluster and your computer this is called port forwarding. Here is how to do it, assuming your pod exposes port You can then open up port on your local computer and that will forward the traffic to the pod MYPOD on its port This is very useful to do a quick check on your pod to verify that it looks OK. You can copy files and directories using the kubectl cp command. It is useful to be able to complete your shell commands, and kubectl has a ready-made solution for that:. Kubectl supports a number of shells, and you will need to consult Kubernetes documentation for more details. Please note you will also need to install the bash-completion package for your Operating System if not already installed. Also, the above command will enable autocompletion only for the current session; to make it permanent, add this command to your shell initialization file. Finally, a very useful command to test your RBAC rules is kubectl auth can-i. Here is an example to test whether a given service account can read a certain config map:. You will obviously need to replace the capitalized placeholders with the names that make sense for your setup. Kubernetes is a complex system, and often, something will go wrong, simply because it can. This process, however, can often run out of hand and turn into a stressful, ineffective, and time-consuming task. This is the reason why we created Komodor, a tool that helps dev and ops teams stop wasting their precious time looking for needles in hay stacks every time things go wrong. If you are interested in checking out Komodor, use this link to sign up for a Free Trial. This website uses cookies. By continuing to browse, you agree to our Privacy Policy. Guides Kubernetes Troubleshooting. What is Kubectl If you are reading this article, you are probably familiar with Kubernetes and want to interact with a Kubernetes cluster. Kubectl offers three techniques. The command for this is kubectl apply -f manifest. Detect and fix errors 5x faster Komodor monitors your entire K8s stack, identifies issues, and uncovers their root cause. Kubectl Get Kubectl get is probably the command you will use the most, so it deserves its own section. Kubectl get offers a range of output formats: -o wide just adds more information which is dependent on the type of objects being queried. Other Commands to Get Information There are many other commands to retrieve information besides kubectl get. Imperative Commands These commands directly instruct Kubernetes to perform a specific operation on a given object. Managing Deployments Here are some useful commands to manage deployments in a general sense, so that also includes stateful sets and daemon sets. Interacting With Pods This section will list a bunch of commands that are very useful to interact with your pods. Kubernetes Troubleshooting With Komodor Kubernetes is a complex system, and often, something will go wrong, simply because it can. Acting as a single source of truth SSOT for all of your k8s troubleshooting needs, Komodor offers: Change intelligence : Every issue is a result of a change. Within seconds we can help you understand exactly who did what and when. In-depth visibility : A complete activity timeline, showing all code and config changes, deployments, alerts, code diffs, pod logs and etc. All within one pane of glass with easy drill-down options. Insights into service dependencies : An easy way to understand cross-service changes and visualize their ripple effects across your entire system. Seamless notifications : Direct integration with your existing communication channels e. Receive blog and product updates. Latest Articles.
1 note · View note