LAB04c: Setting up Cluster Connection
LAB 19: Setting up cluster connect
How to Create a New Kubernetes Context
1. Check what you already have
kubectl config get-contexts
kubectl config view2. Create a new context
kubectl config set-context <context-name> \
--cluster=<cluster-name> \
--user=<user-name> \
--namespace=<namespace-name>kubectl config set-context prod-admin \
--cluster=prod-cluster \
--user=admin-user \
--namespace=prod3. Switch to your new context
Manually Creating a Context
STEP 1 — Get the Required Files From the Remote Server
✔️ 1. API Server endpoint
✔️ 2. CA certificate (ca.crt)
✔️ 3. Client credentials (cert/key OR token)
Copy admin.conf (easiest and most common)
If You Want to Build kubeconfig Manually
STEP 2 — Add the Cluster Info
STEP 3 — Add User Credentials
Option A — With client certificate/key
Option B — With bearer token
STEP 4 — Create the Context
STEP 5 — Use the Context
Test the Connection
How to handle multiple config file
Option 1 — Safest: Merge Using KUBECONFIG Variable (Non-Destructive)
Step 1: Save your new config as a separate file
Step 2: Temporarily merge them
Step 3: Replace the main config with the merged one
Option 2 — Use Multiple Kubeconfigs Without Merging
Use original config:
Use remote cluster:
Make it permanent per-shell:
Option 3 — Create Named Contexts Inside One File (Recommended)
Add cluster:
Add credentials:
Add context:
Switch:
Which option should you use?
Situation
Best Option
Last updated