2017-08-29 00:19:25 +03:00
# Bootstrapping the Kubernetes Worker Nodes
2018-01-18 23:34:11 +03:00
In this lab you will bootstrap three Kubernetes worker nodes. The following components will be installed on each node: [runc ](https://github.com/opencontainers/runc ), [container networking plugins ](https://github.com/containernetworking/cni ), [cri-containerd ](https://github.com/containerd/cri-containerd ), [kubelet ](https://kubernetes.io/docs/admin/kubelet ), and [kube-proxy ](https://kubernetes.io/docs/concepts/cluster-administration/proxies ).
2017-08-29 00:19:25 +03:00
## Prerequisites
The commands in this lab must be run on each worker instance: `worker-0` , `worker-1` , and `worker-2` . Login to each worker instance using the `gcloud` command. Example:
```
gcloud compute ssh worker-0
```
## Provisioning a Kubernetes Worker Node
2017-10-02 06:37:09 +03:00
Install the OS dependencies:
2017-08-29 00:19:25 +03:00
```
2017-10-02 06:37:09 +03:00
sudo apt-get -y install socat
2017-08-29 00:19:25 +03:00
```
2017-10-02 06:37:09 +03:00
> The socat binary enables support for the `kubectl port-forward` command.
2017-08-29 00:19:25 +03:00
### Download and Install Worker Binaries
```
wget -q --show-progress --https-only --timestamping \
https://github.com/containernetworking/plugins/releases/download/v0.6.0/cni-plugins-amd64-v0.6.0.tgz \
2018-01-18 23:34:11 +03:00
https://github.com/containerd/cri-containerd/releases/download/v1.0.0-beta.1/cri-containerd-1.0.0-beta.1.linux-amd64.tar.gz \
2017-12-18 17:53:32 +03:00
https://storage.googleapis.com/kubernetes-release/release/v1.9.0/bin/linux/amd64/kubectl \
https://storage.googleapis.com/kubernetes-release/release/v1.9.0/bin/linux/amd64/kube-proxy \
https://storage.googleapis.com/kubernetes-release/release/v1.9.0/bin/linux/amd64/kubelet
2017-08-29 00:19:25 +03:00
```
Create the installation directories:
```
sudo mkdir -p \
/etc/cni/net.d \
/opt/cni/bin \
/var/lib/kubelet \
/var/lib/kube-proxy \
/var/lib/kubernetes \
/var/run/kubernetes
```
Install the worker binaries:
```
sudo tar -xvf cni-plugins-amd64-v0.6.0.tgz -C /opt/cni/bin/
```
```
2018-01-18 23:34:11 +03:00
sudo tar -xvf cri-containerd-1.0.0-beta.1.linux-amd64.tar.gz -C /
2017-08-29 00:19:25 +03:00
```
```
2017-10-02 06:37:09 +03:00
chmod +x kubectl kube-proxy kubelet
2017-08-29 00:19:25 +03:00
```
```
2017-10-02 06:37:09 +03:00
sudo mv kubectl kube-proxy kubelet /usr/local/bin/
2017-08-29 00:19:25 +03:00
```
### Configure CNI Networking
Retrieve the Pod CIDR range for the current compute instance:
```
POD_CIDR=$(curl -s -H "Metadata-Flavor: Google" \
http://metadata.google.internal/computeMetadata/v1/instance/attributes/pod-cidr)
```
Create the `bridge` network configuration file:
```
cat > 10-bridge.conf < < EOF
{
"cniVersion": "0.3.1",
"name": "bridge",
"type": "bridge",
"bridge": "cnio0",
"isGateway": true,
"ipMasq": true,
"ipam": {
"type": "host-local",
"ranges": [
[{"subnet": "${POD_CIDR}"}]
],
"routes": [{"dst": "0.0.0.0/0"}]
}
}
EOF
```
Create the `loopback` network configuration file:
```
cat > 99-loopback.conf < < EOF
{
"cniVersion": "0.3.1",
"type": "loopback"
}
EOF
```
Move the network configuration files to the CNI configuration directory:
```
sudo mv 10-bridge.conf 99-loopback.conf /etc/cni/net.d/
```
### Configure the Kubelet
```
sudo mv ${HOSTNAME}-key.pem ${HOSTNAME}.pem /var/lib/kubelet/
```
```
sudo mv ${HOSTNAME}.kubeconfig /var/lib/kubelet/kubeconfig
```
```
sudo mv ca.pem /var/lib/kubernetes/
```
Create the `kubelet.service` systemd unit file:
```
cat > kubelet.service < < EOF
[Unit]
Description=Kubernetes Kubelet
2017-12-18 18:07:54 +03:00
Documentation=https://github.com/kubernetes/kubernetes
2017-10-02 06:37:09 +03:00
After=cri-containerd.service
Requires=cri-containerd.service
2017-08-29 00:19:25 +03:00
[Service]
ExecStart=/usr/local/bin/kubelet \\
--allow-privileged=true \\
2017-10-02 06:37:09 +03:00
--anonymous-auth=false \\
--authorization-mode=Webhook \\
--client-ca-file=/var/lib/kubernetes/ca.pem \\
2017-12-18 18:20:15 +03:00
--cloud-provider= \\
2017-08-29 00:19:25 +03:00
--cluster-dns=10.32.0.10 \\
--cluster-domain=cluster.local \\
--container-runtime=remote \\
2017-10-02 06:37:09 +03:00
--container-runtime-endpoint=unix:///var/run/cri-containerd.sock \\
2017-08-29 00:19:25 +03:00
--image-pull-progress-deadline=2m \\
--kubeconfig=/var/lib/kubelet/kubeconfig \\
--network-plugin=cni \\
--pod-cidr=${POD_CIDR} \\
--register-node=true \\
2017-10-02 06:37:09 +03:00
--runtime-request-timeout=15m \\
2017-08-29 00:19:25 +03:00
--tls-cert-file=/var/lib/kubelet/${HOSTNAME}.pem \\
--tls-private-key-file=/var/lib/kubelet/${HOSTNAME}-key.pem \\
--v=2
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
EOF
```
### Configure the Kubernetes Proxy
```
sudo mv kube-proxy.kubeconfig /var/lib/kube-proxy/kubeconfig
```
Create the `kube-proxy.service` systemd unit file:
```
cat > kube-proxy.service < < EOF
[Unit]
Description=Kubernetes Kube Proxy
2017-12-18 18:07:54 +03:00
Documentation=https://github.com/kubernetes/kubernetes
2017-08-29 00:19:25 +03:00
[Service]
ExecStart=/usr/local/bin/kube-proxy \\
--cluster-cidr=10.200.0.0/16 \\
--kubeconfig=/var/lib/kube-proxy/kubeconfig \\
--proxy-mode=iptables \\
--v=2
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
EOF
```
### Start the Worker Services
```
2017-10-02 06:37:09 +03:00
sudo mv kubelet.service kube-proxy.service /etc/systemd/system/
2017-08-29 00:19:25 +03:00
```
```
sudo systemctl daemon-reload
```
```
2017-10-02 06:37:09 +03:00
sudo systemctl enable containerd cri-containerd kubelet kube-proxy
2017-08-29 00:19:25 +03:00
```
```
2017-10-02 06:37:09 +03:00
sudo systemctl start containerd cri-containerd kubelet kube-proxy
2017-08-29 00:19:25 +03:00
```
> Remember to run the above commands on each worker node: `worker-0`, `worker-1`, and `worker-2`.
## Verification
Login to one of the controller nodes:
```
gcloud compute ssh controller-0
```
List the registered Kubernetes nodes:
```
kubectl get nodes
```
> output
```
2017-10-02 06:37:09 +03:00
NAME STATUS ROLES AGE VERSION
2017-12-18 17:53:32 +03:00
worker-0 Ready < none > 18s v1.9.0
worker-1 Ready < none > 18s v1.9.0
worker-2 Ready < none > 18s v1.9.0
2017-08-29 00:19:25 +03:00
```
Next: [Configuring kubectl for Remote Access ](10-configuring-kubectl.md )