/    /  Kubernetes – Kubectl

Kubernetes – Kubectl

 

It is used to communicate and manage pods in Kubernetes clusters through the Kubectl command line utility.

To interact with Kubernetes clusters, one needs to set kubectl to local.

Setting Kubectl

Using curl, download the executable to the local workstation.

On Linux

$ curl -O https://storage.googleapis.com/kubernetesrelease/
release/v1.5.2/bin/linux/amd64/kubectl

Once the download is done, move the binaries to the system’s path.

$ chmod +x kubectl
$ mv kubectl /usr/local/bin/kubectl

Configuring Kubectl

Here’s how to configure it.

$ kubectl config set-cluster default-cluster --server = https://${MASTER-HOST} --
certificate-authority = ${CA-CERT}
$ kubectl config set-credentials default-admin --certificateauthority = ${
CA-CERT} --client-key = ${ADMIN-KEY} --clientcertificate = ${
ADMIN-CERT}
$ kubectl config set-context default-system --cluster = default-cluster --
user = default-admin
$ kubectl config use-context default-system
  • In the previous step, replace $[MASTER-HOST] with the address or name of the master node.
  • The absolute path to the ca.pem you created in the previous step should replace $[CA-CERT].
  • You’ll need to replace $[ADMIN-KEY] with the absolute path to admin-key.pem.
  • Replace  ${ADMIN-CERT}  with the absolute path to admin.pem.

Verifying the Setup

Check if the Kubernetes client is set up right before using kubectl.

$ kubectl get nodes