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 same directory used to generate the admin client certificates.
## The Admin Kubernetes Configuration File
Each kubeconfig requires a Kubernetes API Server to connect to. To support high availability the IP address assigned to the external load balancer fronting the Kubernetes API Servers will be used.
2024-03-18 08:16:56 +03:00
[//]: # (host:controlplane01)
2022-09-20 09:17:00 +03:00
2024-03-18 08:16:56 +03:00
On `controlplane01`
2017-08-29 00:19:25 +03:00
2022-09-20 09:17:00 +03:00
Get the kube-api server load-balancer IP.
```bash
LOADBALANCER=$(dig +short loadbalancer)
2017-08-29 00:19:25 +03:00
```
2022-09-20 09:17:00 +03:00
Generate a kubeconfig file suitable for authenticating as the `admin` user:
```bash
2018-05-12 19:54:18 +03:00
{
2017-08-29 00:19:25 +03:00
2018-05-12 19:54:18 +03:00
kubectl config set-cluster kubernetes-the-hard-way \
2019-03-20 07:34:49 +03:00
--certificate-authority=ca.crt \
2018-05-12 19:54:18 +03:00
--embed-certs=true \
2022-09-20 09:17:00 +03:00
--server=https://${LOADBALANCER}:6443
2017-08-29 00:19:25 +03:00
2018-05-12 19:54:18 +03:00
kubectl config set-credentials admin \
2019-03-20 07:34:49 +03:00
--client-certificate=admin.crt \
--client-key=admin.key
2017-08-29 00:19:25 +03:00
2018-05-12 19:54:18 +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
}
2020-12-20 19:24:20 +03:00
```
2019-11-19 13:31:48 +03:00
Reference doc for kubectl config [here ](https://kubernetes.io/docs/tasks/access-application-cluster/configure-access-multiple-clusters/ )
2017-08-29 00:19:25 +03:00
## Verification
Check the health of the remote Kubernetes cluster:
```
kubectl get componentstatuses
```
2024-03-18 08:16:56 +03:00
Output will be similar to this. It may or may not list both etcd instances, however this is OK if you verified correct installation of etcd in lab 7.
2017-08-29 00:19:25 +03:00
```
2022-09-20 09:17:00 +03:00
Warning: v1 ComponentStatus is deprecated in v1.19+
2018-05-12 19:54:18 +03:00
NAME STATUS MESSAGE ERROR
2017-09-04 00:18:03 +03:00
controller-manager Healthy ok
scheduler Healthy ok
2018-05-12 19:54:18 +03:00
etcd-1 Healthy {"health":"true"}
etcd-0 Healthy {"health":"true"}
2017-08-29 00:19:25 +03:00
```
List the nodes in the remote Kubernetes cluster:
2022-09-20 09:17:00 +03:00
```bash
2017-08-29 00:19:25 +03:00
kubectl get nodes
```
> output
```
2022-09-20 09:17:00 +03:00
NAME STATUS ROLES AGE VERSION
2024-03-18 08:16:56 +03:00
node01 NotReady < none > 118s v1.28.4
node02 NotReady < none > 118s v1.28.4
2017-08-29 00:19:25 +03:00
```
2019-11-19 13:31:48 +03:00
2024-03-18 08:16:56 +03:00
Next: [Deploy Pod Networking ](./13-configure-pod-networking.md )</ br >
Prev: [TLS Bootstrapping Kubernetes Workers ](./11-tls-bootstrapping-kubernetes-workers.md )