# Bootstrapping the Kubernetes Control Plane In this lab you will bootstrap the Kubernetes control plane across three VM instances and configure it for high availability. You will also create a load balancer that exposes the Kubernetes API Servers to remote clients. The following components will be installed on each node: Kubernetes API Server, Scheduler, and Controller Manager. ## Prerequisites The commands in this lab must be run on each controller instance: `controller-0`, `controller-1`, and `controller-2`. Login to each controller instance using the `ssh` command. Example: ```bash ssh controller-0 ``` ### Running commands in parallel with tmux [tmux](https://github.com/tmux/tmux/wiki) can be used to run commands on multiple compute instances at the same time. See the [Running commands in parallel with tmux](01-prerequisites.md#running-commands-in-parallel-with-tmux) section in the Prerequisites lab. ## Provision the Kubernetes Control Plane Create the Kubernetes configuration directory: ```bash sudo mkdir -p /etc/kubernetes/config ``` ### Download and Install the Kubernetes Controller Binaries Download the official Kubernetes release binaries: ```bash wget -q --show-progress --https-only --timestamping \ "https://storage.googleapis.com/kubernetes-release/release/v1.15.3/bin/linux/amd64/kube-apiserver" \ "https://storage.googleapis.com/kubernetes-release/release/v1.15.3/bin/linux/amd64/kube-controller-manager" \ "https://storage.googleapis.com/kubernetes-release/release/v1.15.3/bin/linux/amd64/kube-scheduler" \ "https://storage.googleapis.com/kubernetes-release/release/v1.15.3/bin/linux/amd64/kubectl" ``` Install the Kubernetes binaries: ```bash chmod +x kube-apiserver kube-controller-manager kube-scheduler kubectl sudo mv kube-apiserver kube-controller-manager kube-scheduler kubectl /usr/local/bin/ ``` ### Configure the Kubernetes API Server ```bash sudo mkdir -p /var/lib/kubernetes/ sudo mv ca.pem ca-key.pem kubernetes-key.pem kubernetes.pem \ service-account-key.pem service-account.pem \ encryption-config.yaml /var/lib/kubernetes/ ``` The instance internal IP address will be used to advertise the API Server to members of the cluster. Define the INTERNAL_IP (replace MY_NODE_INTERNAL_IP by the value): ```bash INTERNAL_IP=MY_NODE_INTERNAL_IP ``` > Example for controller-0 : 192.168.8.10 Create the `kube-apiserver.service` systemd unit file: ```bash cat < Allow up to 10 seconds for the Kubernetes API Server to fully initialize. ### Verification ```bash kubectl get componentstatuses --kubeconfig admin.kubeconfig ``` ```bash 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"} ``` Test the nginx HTTP health check proxy: ```bash curl -H "Host: kubernetes.default.svc.cluster.local" -i http://127.0.0.1/healthz ``` ```bash HTTP/1.1 200 OK Server: nginx/1.14.0 (Ubuntu) Date: Sat, 14 Sep 2019 18:34:11 GMT Content-Type: text/plain; charset=utf-8 Content-Length: 2 Connection: keep-alive X-Content-Type-Options: nosniff ok ``` > Remember to run the above commands on each controller node: `controller-0`, `controller-1`, and `controller-2`. ## RBAC for Kubelet Authorization In this section you will configure RBAC permissions to allow the Kubernetes API Server to access the Kubelet API on each worker node. Access to the Kubelet API is required for retrieving metrics, logs, and executing commands in pods. > This tutorial sets the Kubelet `--authorization-mode` flag to `Webhook`. Webhook mode uses the [SubjectAccessReview](https://kubernetes.io/docs/admin/authorization/#checking-api-access) API to determine authorization. The commands in this section will effect the entire cluster and only need to be run once from one of the controller nodes. ```bash ssh controller-0 ``` Create the `system:kube-apiserver-to-kubelet` [ClusterRole](https://kubernetes.io/docs/admin/authorization/rbac/#role-and-clusterrole) with permissions to access the Kubelet API and perform most common tasks associated with managing pods: ```bash cat <> /etc/nginx/nginx.conf stream { upstream controller_backend { server 192.168.8.10:6443; server 192.168.8.11:6443; server 192.168.8.12:6443; } server { listen 6443; proxy_pass controller_backend; health_check; } } EOF ``` Restart the service: ```bash sudo systemctl restart nginx ``` Enable the service: ```bash sudo systemctl enable nginx ``` ### Load Balancer Verification Define the static public IP address (replace MY_PUBLIC_IP_ADDRESS with your public IP address on the `gateway-01` VM): ```bash KUBERNETES_PUBLIC_ADDRESS=MY_PUBLIC_IP_ADDRESS ``` Make a HTTP request for the Kubernetes version info: ```bash curl --cacert ca.pem https://${KUBERNETES_PUBLIC_ADDRESS}:6443/version ``` > output ```bash { "major": "1", "minor": "15", "gitVersion": "v1.15.3", "gitCommit": "2d3c76f9091b6bec110a5e63777c332469e0cba2", "gitTreeState": "clean", "buildDate": "2019-08-19T11:05:50Z", "goVersion": "go1.12.9", "compiler": "gc", "platform": "linux/amd64" } ``` Next: [Bootstrapping the Kubernetes Worker Nodes](09-bootstrapping-kubernetes-workers.md)