Bootstrapping the Kubernetes Worker Nodes

In this lab you will bootstrap three Kubernetes worker nodes. The following components will be installed on each node: runc, container networking plugins, cri-containerd, kubelet, and kube-proxy.

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:

  1. gcloud compute ssh worker-0

Provisioning a Kubernetes Worker Node

Install the OS dependencies:

  1. sudo apt-get -y install socat

The socat binary enables support for the kubectl port-forward command.

Download and Install Worker Binaries

  1. wget -q --show-progress --https-only --timestamping \
  2. https://github.com/containernetworking/plugins/releases/download/v0.6.0/cni-plugins-amd64-v0.6.0.tgz \
  3. https://github.com/kubernetes-incubator/cri-containerd/releases/download/v1.0.0-alpha.0/cri-containerd-1.0.0-alpha.0.tar.gz \
  4. https://storage.googleapis.com/kubernetes-release/release/v1.8.0/bin/linux/amd64/kubectl \
  5. https://storage.googleapis.com/kubernetes-release/release/v1.8.0/bin/linux/amd64/kube-proxy \
  6. https://storage.googleapis.com/kubernetes-release/release/v1.8.0/bin/linux/amd64/kubelet

Create the installation directories:

  1. sudo mkdir -p \
  2. /etc/cni/net.d \
  3. /opt/cni/bin \
  4. /var/lib/kubelet \
  5. /var/lib/kube-proxy \
  6. /var/lib/kubernetes \
  7. /var/run/kubernetes

Install the worker binaries:

  1. sudo tar -xvf cni-plugins-amd64-v0.6.0.tgz -C /opt/cni/bin/
  1. sudo tar -xvf cri-containerd-1.0.0-alpha.0.tar.gz -C /
  1. chmod +x kubectl kube-proxy kubelet
  1. sudo mv kubectl kube-proxy kubelet /usr/local/bin/

Configure CNI Networking

Retrieve the Pod CIDR range for the current compute instance:

  1. POD_CIDR=$(curl -s -H "Metadata-Flavor: Google" \
  2. http://metadata.google.internal/computeMetadata/v1/instance/attributes/pod-cidr)

Create the bridge network configuration file:

  1. cat > 10-bridge.conf <<EOF
  2. {
  3. "cniVersion": "0.3.1",
  4. "name": "bridge",
  5. "type": "bridge",
  6. "bridge": "cnio0",
  7. "isGateway": true,
  8. "ipMasq": true,
  9. "ipam": {
  10. "type": "host-local",
  11. "ranges": [
  12. [{"subnet": "${POD_CIDR}"}]
  13. ],
  14. "routes": [{"dst": "0.0.0.0/0"}]
  15. }
  16. }
  17. EOF

Create the loopback network configuration file:

  1. cat > 99-loopback.conf <<EOF
  2. {
  3. "cniVersion": "0.3.1",
  4. "type": "loopback"
  5. }
  6. EOF

Move the network configuration files to the CNI configuration directory:

  1. sudo mv 10-bridge.conf 99-loopback.conf /etc/cni/net.d/

Configure the Kubelet

  1. sudo mv ${HOSTNAME}-key.pem ${HOSTNAME}.pem /var/lib/kubelet/
  1. sudo mv ${HOSTNAME}.kubeconfig /var/lib/kubelet/kubeconfig
  1. sudo mv ca.pem /var/lib/kubernetes/

Create the kubelet.service systemd unit file:

  1. cat > kubelet.service <<EOF
  2. [Unit]
  3. Description=Kubernetes Kubelet
  4. Documentation=https://github.com/GoogleCloudPlatform/kubernetes
  5. After=cri-containerd.service
  6. Requires=cri-containerd.service
  7. [Service]
  8. ExecStart=/usr/local/bin/kubelet \\
  9. --allow-privileged=true \\
  10. --anonymous-auth=false \\
  11. --authorization-mode=Webhook \\
  12. --client-ca-file=/var/lib/kubernetes/ca.pem \\
  13. --cluster-dns=10.32.0.10 \\
  14. --cluster-domain=cluster.local \\
  15. --container-runtime=remote \\
  16. --container-runtime-endpoint=unix:///var/run/cri-containerd.sock \\
  17. --image-pull-progress-deadline=2m \\
  18. --kubeconfig=/var/lib/kubelet/kubeconfig \\
  19. --network-plugin=cni \\
  20. --pod-cidr=${POD_CIDR} \\
  21. --register-node=true \\
  22. --require-kubeconfig \\
  23. --runtime-request-timeout=15m \\
  24. --tls-cert-file=/var/lib/kubelet/${HOSTNAME}.pem \\
  25. --tls-private-key-file=/var/lib/kubelet/${HOSTNAME}-key.pem \\
  26. --v=2
  27. Restart=on-failure
  28. RestartSec=5
  29. [Install]
  30. WantedBy=multi-user.target
  31. EOF

Configure the Kubernetes Proxy

  1. sudo mv kube-proxy.kubeconfig /var/lib/kube-proxy/kubeconfig

Create the kube-proxy.service systemd unit file:

  1. cat > kube-proxy.service <<EOF
  2. [Unit]
  3. Description=Kubernetes Kube Proxy
  4. Documentation=https://github.com/GoogleCloudPlatform/kubernetes
  5. [Service]
  6. ExecStart=/usr/local/bin/kube-proxy \\
  7. --cluster-cidr=10.200.0.0/16 \\
  8. --kubeconfig=/var/lib/kube-proxy/kubeconfig \\
  9. --proxy-mode=iptables \\
  10. --v=2
  11. Restart=on-failure
  12. RestartSec=5
  13. [Install]
  14. WantedBy=multi-user.target
  15. EOF

Start the Worker Services

  1. sudo mv kubelet.service kube-proxy.service /etc/systemd/system/
  1. sudo systemctl daemon-reload
  1. sudo systemctl enable containerd cri-containerd kubelet kube-proxy
  1. sudo systemctl start containerd cri-containerd kubelet kube-proxy

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:

  1. gcloud compute ssh controller-0

List the registered Kubernetes nodes:

  1. kubectl get nodes

output

  1. NAME STATUS ROLES AGE VERSION
  2. worker-0 Ready <none> 1m v1.8.0
  3. worker-1 Ready <none> 1m v1.8.0
  4. worker-2 Ready <none> 1m v1.8.0

Next: Configuring kubectl for Remote Access