From previous chapter, we were talking about the infrastructure which we’re gonna build. In this chapter, let’s install & setup a k8s cluster, with 2 nodes!

We will start with the Master server first

For this Lab, I’m gonna use Virtual machines to simulate servers. I’m using macOS Catalina 10.15.2, VMWare Fusion Pro 11.5.1, with 3 Ubuntu 18.04 VMs (2 CPUs, 1GB RAM, bridged network):

  • kube: master (IP: 192.168.1.33)
  • kube1: node 1 (IP: 192.168.1.34)
  • kube2: node 2 (IP: 192.168.1.35)

Before everything, note that:

  • Kubernetes won’t run if swap enabled
  • Kubernetes master-nodes communication will require some ports opened
  • Kubernetes could face some problems with SELINUX

Alright, let’s start with the Master VM.

$ 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 kube
  • (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.33/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
  • Init Kubeadm
$ kubeadm init --pod-network-cidr=10.244.0.0/16

After Kubeadm inited, it will give you a command with token to run it on Node servers:

kubeadm join 192.168.1.33:6443 --token xxx --discovery-token-ca-cert-hash xxx

Create k8s config place

$ mkdir -p $HOME/.kube
$ sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
$ sudo chown $(id -u):$(id -g) $HOME/.kube/config
  • Create Virtual network

We’re gonna use flannel for Virtual network

$ kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
  • (Optional) Create Docker registry

For this Lab, we’re gonna setup a local insecure Docker registry to store our built images.

$ docker run -d -p 5000:5000 --name registry registry:2

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

(Remember 192.168.1.33 is our Master server’s IP)

  • Install metrics server
$ cd /etc
$ git clone https://github.com/kubernetes-incubator/metrics-server.git
$ cd metrics-server/

Edit file /etc/metrics-server/deploy/1.8+/metrics-server-deployment.yaml

      - name: metrics-server
        image: k8s.gcr.io/metrics-server-amd64:v0.3.6
        args:
          - --cert-dir=/tmp
          - --secure-port=4443
        command:
          - /metrics-server
          - --metric-resolution=5s
          - --kubelet-insecure-tls
          - --kubelet-preferred-address-types=InternalIP

Great, you have a working Master server now.

…To be continued

Next chapter https://www.martinpham.com/2019/12/08/having-fun-with-kubernetes-5/