kubernetes-the-hard-way/docs/10-configuring-kubectl.md

82 lines
2.0 KiB
Markdown
Raw Normal View History

2017-08-29 00:19:25 +03:00
# Configuring kubectl for Remote Access
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.
2017-08-29 00:19:25 +03:00
## The Admin Kubernetes Configuration File
Each kubeconfig requires a Kubernetes API Server to connect to.
2017-08-29 00:19:25 +03:00
You should be able to ping `server.kubernetes.local` based on the `/etc/hosts` DNS entry from a previous lap.
2017-08-29 00:19:25 +03:00
```bash
curl -k --cacert ca.crt \
https://server.kubernetes.local:6443/version
2017-08-29 00:19:25 +03:00
```
```text
{
"major": "1",
"minor": "28",
"gitVersion": "v1.28.3",
"gitCommit": "a8a1abc25cad87333840cd7d54be2efaf31a3177",
"gitTreeState": "clean",
"buildDate": "2023-10-18T11:33:18Z",
"goVersion": "go1.20.10",
"compiler": "gc",
"platform": "linux/arm64"
}
```
2017-08-29 00:19:25 +03:00
Generate a kubeconfig file suitable for authenticating as the `admin` user:
```bash
{
kubectl config set-cluster kubernetes-the-hard-way \
--certificate-authority=ca.crt \
--embed-certs=true \
--server=https://server.kubernetes.local:6443
2017-08-29 00:19:25 +03:00
kubectl config set-credentials admin \
--client-certificate=admin.crt \
--client-key=admin.key
2017-08-29 00:19:25 +03:00
kubectl config set-context kubernetes-the-hard-way \
--cluster=kubernetes-the-hard-way \
--user=admin
kubectl config use-context kubernetes-the-hard-way
}
2017-08-29 00:19:25 +03:00
```
The results of running the command above should create a kubeconfig file in the default location `~/.kube/config` used by the `kubectl` commandline tool. This also means you can run the `kubectl` command without specifying a config.
2017-08-29 00:19:25 +03:00
## Verification
2021-05-02 08:33:46 +03:00
Check the version of the remote Kubernetes cluster:
2017-08-29 00:19:25 +03:00
```bash
2021-05-02 08:33:46 +03:00
kubectl version
2017-08-29 00:19:25 +03:00
```
```text
Client Version: v1.28.3
Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3
Server Version: v1.28.3
2017-08-29 00:19:25 +03:00
```
List the nodes in the remote Kubernetes cluster:
```bash
2017-08-29 00:19:25 +03:00
kubectl get nodes
```
```
NAME STATUS ROLES AGE VERSION
node-0 Ready <none> 30m v1.28.3
node-1 Ready <none> 35m v1.28.3
2017-08-29 00:19:25 +03:00
```
Next: [Provisioning Pod Network Routes](11-pod-network-routes.md)