Kubernetes at the command line: Up and running with 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.

Download the kubeconfig

To obtain a kubeconfig customized to your cluster, navigate to the Platform9 clusters page and click the kubeconfig link.

This will download a kubeconfig file for the specific cluster.

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>

Download kubectl

kubectl is an executable binary built specifically for combinations of OS 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.

To identify the Kubernetes version of your cluster, navigate to Infrastructure>Clusters on the Platform9 Clarity UI. Check the value in the Kubernetes version column for your cluster.

If you are using Linux, you can download kubectl, make it executable, and move
it to /usr/local/bin by using the following commands:
[bash linenum=”false”]curl -Lo kubectl http://storage.googleapis.com/kubernetes-release/release/<kubernetes version>/bin/linux/amd64/kubectl
chmod +x kubectl && sudo mv kubectl /usr/local/bin/[/bash] To install kubectl on other operating systems, refer to https://kubernetes.io/docs/tasks/tools/install-kubectl/#install-kubectl-binary-via-curl

Using kubectl

To see the nodes in your cluster
[bash]kubectl get nodes[/bash] Let’s make a Deployment with one nginx Pod:
[bash]kubectl run nginx-example –image=nginx –port=80[/bash] And watch the Pods as they are created (Ctrl-C to stop):
[bash]kubectl get pods –watch[/bash] Finally, delete the Deployment. The Pod will be deleted automatically.

[bash]kubectl delete deployment nginx-example[/bash] For more details, see the Kubernetes overview for kubectl.

The browser you are using is outdated. For the best experience please download or update your browser to one of the following:

State of Kubernetes FinOps Survey – Win 13 prizes including a MacBook Air.Start Now