Kubernetes. Part 3: Installing Kubernetes on Ubuntu 18.04

All parts of the series “Kubernetes”

Disabling swap

Before we start, we need to disable swap. Edit /etc/fstab and remove everything related to swap there. Then run:

sudo swapoff -a

Now we're ready to begin.

Installing kubelet kubeadm kubectl:

sudo apt-get update && sudo apt-get install -y apt-transport-https curl

curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -

cat <<EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
EOF
	
sudo apt-get update

sudo apt-get install -y kubelet kubeadm kubectl

sudo apt-mark hold kubelet kubeadm kubectl

Initializing the cluster:

sudo kubeadm init --pod-network-cidr=10.244.0.0/16

If everything succeeded, copy kubeconfig, having first saved the token and the hash for joining the cluster. The token and the hash should be displayed on the screen at this point.

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

Configuring the network:

sudo sysctl net.bridge.bridge-nf-call-iptables=1
wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

Edit the kube-flannel.yml file and bring it in line with the following fragment:

cni-conf.json: |
    {
      "name": "vxlan0",
      "plugins": [
        {
          "type": "flannel",
          "delegate": {
            "hairpinMode": true,
            "isDefaultGateway": true
          }
        },
        {
          "type": "portmap",
          "capabilities": {
            "portMappings": true
          }
        }
      ]
    }
net-conf.json: |
    {
      "Network": "10.244.0.0/16",
      "Backend": {
        "Type": "vxlan",
        "VNI" : 4096,
        "Port": 4789
      }
    }

Send the file to kubernetes:

kubectl apply -f kube-flannel.yml

All that's left is to check that everything works:

kubectl get nodes -o wide

Only registered users can leave a comment.

Sign in or register to leave a comment.