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-01-29 20:40:01 +03:00
Extract the public IP address of the cluster:
```gcloud```
```
KUBERNETES_PUBLIC_ADDRESS=$(gcloud compute addresses describe kubernetes-the-hard-way \
--region $(gcloud config get-value compute/region) \
--format 'value(address)')
```
```az```
```
KUBERNETES_PUBLIC_ADDRESS=$(az network public-ip show --name kubernetes-the-hard-way --query ipAddress -o tsv)
```
2017-08-29 00:19:25 +03:00
Generate a kubeconfig file suitable for authenticating as the `admin` user:
```
2024-01-29 20:40:01 +03:00
kubectl config set-cluster kubernetes-the-hard-way \
--certificate-authority=ca.pem \
--embed-certs=true \
--server=https://${KUBERNETES_PUBLIC_ADDRESS}:6443
kubectl config set-credentials admin \
--client-certificate=admin.pem \
--client-key=admin-key.pem
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
```
## 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
```
2021-05-02 08:33:46 +03:00
kubectl version
2017-08-29 00:19:25 +03:00
```
> output
```
2021-05-02 08:33:46 +03:00
Client Version: version.Info{Major:"1", Minor:"21", GitVersion:"v1.21.0", GitCommit:"cb303e613a121a29364f75cc67d3d580833a7479", GitTreeState:"clean", BuildDate:"2021-04-08T16:31:21Z", GoVersion:"go1.16.1", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"21", GitVersion:"v1.21.0", GitCommit:"cb303e613a121a29364f75cc67d3d580833a7479", GitTreeState:"clean", BuildDate:"2021-04-08T16:25:06Z", GoVersion:"go1.16.1", Compiler:"gc", Platform:"linux/amd64"}
2017-08-29 00:19:25 +03:00
```
List the nodes in the remote Kubernetes cluster:
```
kubectl get nodes
```
> output
```
2020-07-18 10:24:55 +03:00
NAME STATUS ROLES AGE VERSION
2021-05-02 08:33:46 +03:00
worker-0 Ready < none > 2m35s v1.21.0
worker-1 Ready < none > 2m35s v1.21.0
worker-2 Ready < none > 2m35s v1.21.0
2017-08-29 00:19:25 +03:00
```
Next: [Provisioning Pod Network Routes ](11-pod-network-routes.md )