Kubectl
Kubernetes provides a command-line interface (CLI) called kubectl to deploy, troubleshoot, and manage applications. Before you can use kubectl, you must ensure you can authenticate with the cluster’s API server. Your credentials are distributed in a file called a kubeconfig, which is read by kubectl.
Before you can run the kubectl CLI to access your PMK cluster, you must first download the kubeconfig for that cluster, that can then be used by kubectl.
Make kubeconfig discoverable by kubectl
By default, kubectl reads the kubeconfig file that is stored at the following path in your system’s home directory: ~/.kube/config
PMK recommends you to place your kubeconfig under~/.kube/config. If your kubeconfig is located at a different path, you can pass that path to kubectl using the option --kubeconfig
Download kubectl
kubectl is an executable binary built specifically for a variety of Operating System and CPU architectures.
Before you can download kubectl, you must identify the version of kubectl to download. The kubectl version must match the Kubernetes version of your cluster.
Follow these steps to identify the Kubernetes version of your cluster.
- Navigate to Infrastructure > Clusters in the PMK UI.
- Identify your cluster in the Clusters Tab and check the value in the Kubernetes version column for your cluster.
Follow the instructions here to Install kubectl on Linux
To install kubectl on other operating systems, refer to Kubernetes kubectl install documentation.
Make kubeconfig discoverable by kubectl
kubectl will by default read the file ~/.kube/config We recommend placing your kubeconfig there. Otherwise, you can pass kubectl the option --kubeconfig <path to config />
Using kubectl
The complete kubectl reference can be found here.
Below are some example commands can you run.
Get all nodes in a cluster.
kubectl get nodesLet’s make a Deployment with one nginx Pod:
kubectl run nginx-example --image=nginx --port=80And watch the Pods as they are created (Ctrl-C to stop):
kubectl get pods --watchFinally, delete the Deployment. The Pod will be deleted automatically.
kubectl delete deployment nginx-exampleFor more details, see the Kubectl Overview.