kubectl
is a command-line program for interacting with the Kubernetes API. The following steps should be done from a local workstation to configure kubectl
to work with a new cluster.
Download kubectl
from the Kubernetes release artifact site with the curl
tool.
The linux kubectl
binary can be fetched with a command like:
$ curl -O https://storage.googleapis.com/kubernetes-release/release/v1.2.4/bin/linux/amd64/kubectl
On an OS X workstation, replace linux
in the URL above with darwin
:
$ curl -O https://storage.googleapis.com/kubernetes-release/release/v1.2.4/bin/darwin/amd64/kubectl
After downloading the binary, ensure it is executable and move it into your PATH
:
$ chmod +x kubectl
$ mv kubectl /usr/local/bin/kubectl
Configure kubectl
to connect to the target cluster using the following commands, replacing several values as indicated:
${MASTER_HOST}
with the master node address or name used in previous steps${CA_CERT}
with the absolute path to the ca.pem
created in previous steps${ADMIN_KEY}
with the absolute path to the admin-key.pem
created in previous steps${ADMIN_CERT}
with the absolute path to the admin.pem
created in previous steps$ kubectl config set-cluster default-cluster --server=https://${MASTER_HOST} --certificate-authority=${CA_CERT}
$ kubectl config set-credentials default-admin --certificate-authority=${CA_CERT} --client-key=${ADMIN_KEY} --client-certificate=${ADMIN_CERT}
$ kubectl config set-context default-system --cluster=default-cluster --user=default-admin
$ kubectl config use-context default-system
Check that the client is configured properly by using kubectl
to inspect the cluster:
$ kubectl get nodes
NAME LABELS STATUS
X.X.X.X kubernetes.io/hostname=X.X.X.X Ready