DEV Community

Cover image for πŸŽ₯ Setting up a Kubernetes Cluster - Live Stream Replay (with notes)
Nathan Bland
Nathan Bland

Posted on

πŸŽ₯ Setting up a Kubernetes Cluster - Live Stream Replay (with notes)

Ever wanted to setup your own Kubernetes(k8s) cluster for development? Wanted to go a bit further than using minikube? We'll walk through setting up 3 vms to create our very own k8 cluster.

Video - notes below

Notes and Summary

notes

  • The first ~30 minutes of this are VM install and setup, feel free to skip that.
  • The GUI I'm using for KVMs is virt-manager.
  • I did not have virtualization turned on in my system bios (new system didn't have the switch flipped yet) so this severely impacted performance.
  • virt-clone should have provisioned a different mac address for each VM clone, still not sure what happened there.

Summary

Most of the instructions I ran through aside from networking woes can be boiled down to this:

1. Setup support for installing packages over https

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

2. Add trusted key for packages we want to install

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

3. Add repository for Kubernetes(k8s)

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

4. Update package listings

sudo apt-get update

5. Install kubernetes, its tools, and docker.io

sudo apt install kubectl kubeadm docker.io

6. Disable swap memory. (it isn't supported)

sudo swapoff -a

You'll also want to remove the swap entry from fstab so you don't have to do this every time your system comes up (vm or bare metal).

sudo nano /etc/fstab

Remove the entire line with swap, but nothing else, be careful here.

7. Enable and start the docker service.

sudo systemctl enable docker.service

8. Setup the Docker Daemon

sudo nano /etc/docker/daemon.json

{
  "exec-opts": ["native.cgroupdriver=systemd"],
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "100m"
  },
  "storage-driver": "overlay2"
}
Enter fullscreen mode Exit fullscreen mode

sudo mkdir -p /etc/systemd/system/docker.service.d

9. Reload the docker daemon and system process

sudo systemctl daemon-reload && sudo systemctl restart docker

10. Clone our VM.

At this point you can clone your VM, you should be able to do this and get the same installs, but with different network MAC addresses. Some issues with my own setup prevented this from going smoothly, but this is the time to clone the VM if you want to go that route.

Spin up two clones of our first VM. You'll need to change the hostname at a minimum, and reboot (or restart the networking service).

sudo nano /etc/hostname

I used kube-worker-1 and kube-worker-2, but use whatever you like. So long as it doesn't have _ or CAPS characters. I learned that the hard way.

sudo reboot

Steps on our Manager node

1. Initialize our k8 cluster

sudo kubeadm config images pull - (optional) The next command will do this by default, but it can take a while, my sanity prefers pulling the images first.

sudo kubeadm init

After running this command, you'll get output similar to this:

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

Along with a join command for the cluster. Copy this, save it to a safe place. You'll need it later.

If you lose this token, you can make a new one with:

kubeadm token create --print-join-command

2. Establish Cluster Network - Using Weave

kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"

3. View the networking services we just spun up

kubectl get pods --all-namespaces

Steps on our Worker nodes

1. Join our cluster

sudo kubeadm join .... - This should be the command you copied/saved form the init command above.

Back to the Manager Node

We can now check the status of our cluster:

kubectl get nodes

Profit

Links:

Latest comments (0)