Having fun with Kubernetes #5

You had your first k8s master server, now it’s time to setup our nodes and connect them.

Let’s start on Kube1 (192.168.1.34)

$ sudo su
  • Disable swap
$ swapoff -a

Also don’t forget to disable swap on reboot, by edit /etc/fstab file

  • (Optional) Set hostname
$ hostnamectl set-hostname kube1
  • (Optional) Set static IP

Edit file /etc/netplan/50-cloud-init.yaml to set static IP

network:
    renderer: networkd
    ethernets:
        ens33:
            dhcp4: no
            addresses: [192.168.1.34/24]
            gateway4: 192.168.1.1
            nameservers:
                addresses: [8.8.8.8,8.8.4.4]
    version: 2
  • Update apt
$ apt update
  • Install Docker
$ apt install docker.io

Auto start Docker

$ systemctl enable docker

Start Docker

$ systemctl start docker
  • Install Kubeadm
$ curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add

$ apt-add-repository "deb http://apt.kubernetes.io/ kubernetes-xenial main"

$ apt install kubeadm
  • Join this node to the master

This command was generated when you setup your Master server

$ kubeadm join xxx:6443 --token xxx --discovery-token-ca-cert-hash xxx
  • (Optional) Docker registry

As I told, for some funny security reasons, Docker doesn’t want to connect to an insecure registry.

To allow Docker to use insecure registry, you need to:

Edit file /etc/docker/daemon.json

{
        "insecure-registries" : ["192.168.1.33:5000"]
}

Edit file /etc/default/docker

DOCKER_OPTS="--insecure-registry 192.168.1.33:5000"

Restart Docker

$ service docker restart

Repeat the same, for Kube2 (don’t forget the hostname and static IP)

Now you have a working k8s cluster with Master and 2 Nodes.

…To be continued

Final chapter: https://www.martinpham.com/2019/12/14/having-fun-with-kubernetes-final/

Leave a Reply

Your email address will not be published. Required fields are marked *