Connecting to a Kubernetes Cluster

Learn how to connect to a Kubernetes cluster for efficient management and development.

Projects: c2platform/ansible


Prerequisites

Before you can connect to a cluster, ensure you have a Kubernetes cluster, such as one running on c2d-ks1, c2d-awx1, or c2d-galaxy1 in place. For detailed instructions on setting up these clusters, refer to the following resources:

Create ~/.kube/config File

To connect to a Kubernetes cluster, you need to create a ~/.kube/config file. Here’s an example of how to do this:

sudo snap install kubectl --classic
export BOX=c2d-awx1
mkdir --parents ~/.kube
vagrant ssh $BOX -c "microk8s config" > ~/.kube/config

Verify the Connection

To ensure that you’ve successfully connected to the cluster, you can use any kubectl command. For example, run the following command to verify your connection:

kubectl get all --all-namespaces

Visual Studio Code Integration

If you use Visual Studio Code, you can enhance your Kubernetes cluster management experience by installing the Visual Studio Code Kubernetes Tools  . With this extension, you can seamlessly connect to and manage your Kubernetes cluster directly from Visual Studio Code.