- Lab
- A Cloud Guru
Configuring Kubectl to Access a Remote Cluster
Kubectl is a powerful tool for managing a Kubernetes cluster. While kubectl can be used from one of the servers that makes up your cluster, it can also be used from your local command line to manage the cluster remotely. In this learning activity, you will configure kubectl on one machine to interact with a Kubernetes cluster on another machine. After completing this activity, you will have hands-on experience in configuring kubectl to connect to a cluster remotely.
Path Info
Table of Contents
-
Challenge
Set the kubectl cluster data.
You can set the cluster data like this. Be sure to set
KUBERNETES_PUBLIC_ADDRESS
to the public IP of your controller.KUBERNETES_PUBLIC_ADDRESS=<Controller public IP> kubectl config set-cluster kubernetes-the-hard-way --certificate-authority=ca.pem --embed-certs=true --server=https://${KUBERNETES_PUBLIC_ADDRESS}:6443
-
Challenge
Set the credentials for kubectl.
The credentials are the certificate and key files
admin.pem
andadmin-key.pem
. These can be found in the home directory on the workspace server. You can set them up for kubectl like this:kubectl config set-credentials admin --client-certificate=admin.pem --client-key=admin-key.pem
-
Challenge
Set the context for the cluster.
Set the context like this:
kubectl config set-context kubernetes-the-hard-way --cluster=kubernetes-the-hard-way --user=admin
-
Challenge
Use the new kubectl context to check which pods are currently running on the cluster.
Configure kubectl to use the new context like this:
kubectl config use-context kubernetes-the-hard-way
Verify that everything is working with:
kubectl get pods
Since there are no pods right now, you should get the following response:
No resources found.
This indicates that kubectl is set up correctly to access the cluster!
What's a lab?
Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.
Provided environment for hands-on practice
We will provide the credentials and environment necessary for you to practice right within your browser.
Guided walkthrough
Follow along with the author’s guided walkthrough and build something new in your provided environment!
Did you know?
On average, you retain 75% more of your learning if you get time for practice.