You are browsing a read-only backup copy of Wikitech. The primary site can be found at wikitech.wikimedia.org
kubectl is the Kubernetes command-line tool to deploy and manage applications on a Kubernetes cluster.
On Debian 9 (also known as Debian Stretch) it is included in the package kubernetes-client.
kubectl can be used to view and troubleshoot cluster components and to do certain maintenance tasks. See also the kubectl cheatsheet/.
<inputbox> type=fulltext prefix="Kubernetes" searchbuttonlabel= Search placeholder=Search Kubernetes Documentation width=35 break=no </inputbox>
kubectl needs to know how to connect to the cluster and what credentials to use. This information can be stored in the kubeconfig file. By default
kubectl uses a variable called
KUBECONFIG to find this kubeconfig file. If the variable is not set, it looks in
In order to have
kubectl working with your service the KUBECONFIG variable has to be set. This is of the form:
It is easier to use kube_env for this purpose, see below.
Running kubectl Commands
For example to get a list of pods for a service:
KUBECONFIG="/etc/kubernetes/termbox-staging.config" kubectl get pods
kube_env (present on deploy hosts) simplifies the configuration of
kubectl and the access to different clusters and services. Use the following command to setup the
KUBECONFIG variable (and many other useful variables like namespace and helm variables):
kube_env $SERVICE $CLUSTER
Then you can use
kubectl to access the service:
kubectl get pods
Describe a pod
If there is an issue with a pod not starting and logs don't say anything, use "describe" to get more info. For example:
kubectl describe pod P -n sessionstore