Lab 10: Configuring kubectl
for Remote Access¶
This is a fork of the original "Kubernetes the hard way" originally written by Kelsey Hightower (GitHub: kelseyhightower). Unlike the original that bases itself on Debian like distributions for the ARM64 architecture, this fork targets Enterprise Linux distributions such as Rocky Linux running on x86_64 architecture.
In this lab you will generate a kubeconfig file for the kubectl
command line utility based on the admin
user credentials.
Run the commands in this lab from the
jumpbox
machine.
The Admin Kubernetes Configuration File¶
Each kubeconfig requires a Kubernetes API Server to connect to.
You should be able to ping server.kubernetes.local
based on the /etc/hosts
DNS entry from an earlier lab.
curl -k --cacert ca.crt \
https://server.kubernetes.local:6443/version
{
"major": "1",
"minor": "32",
"gitVersion": "v1.32.0",
"gitCommit": "70d3cc986aa8221cd1dfb1121852688902d3bf53",
"gitTreeState": "clean",
"buildDate": "2024-12-11T17:59:15Z",
"goVersion": "go1.23.3",
"compiler": "gc",
"platform": "linux/amd64"
}
Generate a kubeconfig file suitable for authenticating as the admin
user:
kubectl config set-cluster kubernetes-the-hard-way \
--certificate-authority=ca.crt \
--embed-certs=true \
--server=https://server.kubernetes.local:6443
kubectl config set-credentials admin \
--client-certificate=admin.crt \
--client-key=admin.key
kubectl config set-context kubernetes-the-hard-way \
--cluster=kubernetes-the-hard-way \
--user=admin
kubectl config use-context kubernetes-the-hard-way
The results of running the command above should create a kubeconfig file in the default location ~/.kube/config
used by the kubectl
command line tool. This also means you can run the kubectl
command without specifying a config.
Verification¶
Check the version of the remote Kubernetes cluster:
kubectl version
Client Version: v1.32.0
Kustomize Version: v5.5.0
Server Version: v1.32.0
List the nodes in the remote Kubernetes cluster:
kubectl get nodes
NAME STATUS ROLES AGE VERSION
node-0 Ready <none> 30m v1.31.2
node-1 Ready <none> 35m v1.31.2
Next: Provisioning Pod Network Routes
Author: Wale Soyinka
Contributors: Steven Spencer