Skip to content

Instantly share code, notes, and snippets.

@mishan
Last active March 20, 2019 07:24
Show Gist options
  • Save mishan/e8957e40b704206b9c50b30e241fc04c to your computer and use it in GitHub Desktop.
Save mishan/e8957e40b704206b9c50b30e241fc04c to your computer and use it in GitHub Desktop.
how to install single node k8 on Linux for dev

Linux installation

Creating a single-node Kubernetes cluster on Linux. For developers that use Linux on their desktop.

Install Docker

Install Docker. On Debian, you may install the docker.io package from Debian or docker-ce from Docker.

Install Kubernetes

Install kubeadm (https://kubernetes.io/docs/setup/independent/install-kubeadm/)

Initialize a cluster

Initialize a cluster with kubeadm and give it a pod-network-cidr and service-cidr. We need this for kube-router to work. Choose something that doesn't conflict with existing routes to your machine. At time of writing, 172.20.0.0/16 is available. Let's divide it up.

The pod network will get 172.20.0.0/17. The service network will get 172.20.128.0/17.

$ sudo kubeadm init --pod-network-cidr=172.20.0.0/17 --service-cidr=172.20.128.0/17

At the end it will tell you to run the following as a regular user.

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

Install kube-router networking

Per the "Installing a pod network add-on" instructions at https://kubernetes.io/docs/setup/independent/create-cluster-kubeadm/

The preqreuisite for kube-router is that we initialized our Kubernetes cluster with --pod-network-cidr specified, which we've already done.

Run the command below to install kube-router.

$ kubectl apply -f https://raw.githubusercontent.com/cloudnativelabs/kube-router/master/daemonset/kubeadm-kuberouter.yaml

Install Metal LB

You will need to install MetalLB (https://metallb.universe.tf/) or a similar pod to get load balancers to work. This will do the job of provisioning load balancers. Follow the instructions on https://metallb.universe.tf/tutorial/layer2/

$ kubectl apply -f https://raw.githubusercontent.com/google/metallb/v0.7.3/manifests/metallb.yaml

Create a YML file with your configuration per the tutorial. Here it is with our network from above. We will use part of the network from the pod-network-cidr here.

apiVersion: v1
kind: ConfigMap
metadata:
  namespace: metallb-system
  name: config
data:
  config: |
    address-pools:
    - name: tmg-lbs
      protocol: layer2
      addresses:
      - 172.20.120.1-172.20.127.255

Run kubectl apply -f on that file.

Remove taint on master node

By default, your cluster will not schedule pods on the master for security reasons. Run this to fix that.

kubectl taint nodes --all node-role.kubernetes.io/master-

Tearing down Kubernetes

In order to tear down the Kubernetes cluster entirely, one should make sure to clean up any leftover state.

The following commands are recommended to be run as root:

kubeadm reset # this will prompt you
systemctl stop kubelet
systemctl stop docker
rm -rf /var/lib/cni/
rm -rf /var/lib/kubelet/*
rm -rf /etc/cni/
ifconfig kube-bridge down
ifconfig docker0 down
brctl delbr kube-bridge # brctl comes with bridge-utils in Debian
systemctl start docker

While technically kubeadm reset should be sufficient to tear down the cluster, there have been issues with getting clusters to work afterward. See kubernetes/kubernetes#39557

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment