Skip to content

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
  • Labs icon Lab
  • A Cloud Guru
Google Cloud Platform icon
Labs

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.

Google Cloud Platform icon
Labs

Path Info

Level
Clock icon Intermediate
Duration
Clock icon 1h 0m
Published
Clock icon Sep 28, 2018

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.

Table of Contents

  1. 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
    
  2. Challenge

    Set the credentials for kubectl.

    The credentials are the certificate and key files admin.pem and admin-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
    
  3. 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
    
  4. 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!

The Cloud Content team comprises subject matter experts hyper focused on services offered by the leading cloud vendors (AWS, GCP, and Azure), as well as cloud-related technologies such as Linux and DevOps. The team is thrilled to share their knowledge to help you build modern tech solutions from the ground up, secure and optimize your environments, and so much more!

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.

Start learning by doing today

View Plans