kubernetes-the-hard-way/docs/06-kubectl.md

101 lines
2.4 KiB
Markdown
Raw Normal View History

2016-07-07 23:28:46 +03:00
# Configuring the Kubernetes Client - Remote Access
2016-07-07 23:02:28 +03:00
Run the following commands from the machine which will be your Kubernetes Client
2016-07-07 23:26:27 +03:00
## Download and Install kubectl
2016-07-07 23:02:28 +03:00
2016-07-07 23:26:27 +03:00
### OS X
```
wget https://storage.googleapis.com/kubernetes-release/release/v1.5.1/bin/darwin/amd64/kubectl
2016-07-08 14:23:46 +03:00
chmod +x kubectl
2016-07-09 06:59:01 +03:00
sudo mv kubectl /usr/local/bin
2016-07-07 23:26:27 +03:00
```
### Linux
```
wget https://storage.googleapis.com/kubernetes-release/release/v1.5.1/bin/linux/amd64/kubectl
2016-07-08 14:23:46 +03:00
chmod +x kubectl
2016-07-09 06:59:01 +03:00
sudo mv kubectl /usr/local/bin
2016-07-07 23:26:27 +03:00
```
## Configure Kubectl
2016-07-07 23:02:28 +03:00
2016-07-11 20:47:34 +03:00
In this section you will configure the kubectl client to point to the [Kubernetes API Server Frontend Load Balancer](04-kubernetes-controller.md#setup-kubernetes-api-server-frontend-load-balancer).
2016-07-07 23:39:33 +03:00
2016-09-11 09:07:39 +03:00
### GCE
2016-07-07 23:39:33 +03:00
```
2016-09-11 13:53:13 +03:00
KUBERNETES_PUBLIC_ADDRESS=$(gcloud compute addresses describe kubernetes \
2016-07-09 03:45:22 +03:00
--format 'value(address)')
2016-07-07 23:39:33 +03:00
```
2016-09-11 09:07:39 +03:00
### AWS
```
2016-09-11 13:53:13 +03:00
KUBERNETES_PUBLIC_ADDRESS=$(aws elb describe-load-balancers \
2016-09-11 09:07:39 +03:00
--load-balancer-name kubernetes | \
jq -r '.LoadBalancerDescriptions[].DNSName')
```
---
2016-07-07 23:39:33 +03:00
Recall the token we setup for the admin user:
```
2016-08-21 12:31:39 +03:00
# /var/lib/kubernetes/token.csv on the controller nodes
2016-07-07 23:39:33 +03:00
chAng3m3,admin,admin
```
2016-07-11 20:47:34 +03:00
Also be sure to locate the CA certificate [created earlier](02-certificate-authority.md). Since we are using self-signed TLS certs we need to trust the CA certificate so we can verify the remote API Servers.
2016-07-07 23:39:33 +03:00
### Build up the kubeconfig entry
The following commands will build up the default kubeconfig file used by kubectl.
2016-07-07 23:26:27 +03:00
```
kubectl config set-cluster kubernetes-the-hard-way \
--certificate-authority=ca.pem \
2016-07-09 03:46:16 +03:00
--embed-certs=true \
2016-09-11 13:53:13 +03:00
--server=https://${KUBERNETES_PUBLIC_ADDRESS}:6443
2016-07-07 23:02:28 +03:00
```
2016-07-07 23:39:33 +03:00
```
kubectl config set-credentials admin --token chAng3m3
```
2016-07-07 23:02:28 +03:00
```
2016-07-07 23:26:27 +03:00
kubectl config set-context default-context \
--cluster=kubernetes-the-hard-way \
--user=admin
2016-07-07 23:02:28 +03:00
```
```
2016-07-07 23:26:27 +03:00
kubectl config use-context default-context
2016-07-07 23:02:28 +03:00
```
2016-07-07 23:26:27 +03:00
At this point you should be able to connect securly to the remote API server:
```
kubectl get componentstatuses
```
```
NAME STATUS MESSAGE ERROR
controller-manager Healthy ok
scheduler Healthy ok
etcd-2 Healthy {"health": "true"}
etcd-0 Healthy {"health": "true"}
etcd-1 Healthy {"health": "true"}
```
```
kubectl get nodes
```
2016-07-07 23:02:28 +03:00
```
2016-07-07 23:26:27 +03:00
NAME STATUS AGE
2016-07-09 03:47:17 +03:00
worker0 Ready 7m
worker1 Ready 5m
worker2 Ready 2m
2016-07-11 20:47:34 +03:00
```