Skip to content

Instantly share code, notes, and snippets.

@mattsdni
Created October 22, 2018 16:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattsdni/762da9a6397c1d5c78edb0a292e8317c to your computer and use it in GitHub Desktop.
Save mattsdni/762da9a6397c1d5c78edb0a292e8317c to your computer and use it in GitHub Desktop.

Kubernetes Bare Metal

This guide shows how to install Kubernetes on a bare metal device.

Initial package installation

sudo apt-get update && sudo apt-get install -y apt-transport-https
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
sudo touch /etc/apt/sources.list.d/kubernetes.list 
echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee -a /etc/apt/sources.list.d/kubernetes.list
sudo apt-get update
sudo apt-get install kubelet kubeadm kubectl jq 

Turn off swap

sudo swapoff -a

Run kubeadm

sudo kubeadm init  --pod-network-cidr=192.168.0.0/16
Your Kubernetes master has initialized successfully!

To start using your cluster, you need 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

You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
  https://kubernetes.io/docs/concepts/cluster-administration/addons/

You can now join any number of machines by running the following on each node
as root:

  kubeadm join 10.39.27.222:6443 --token ajgrb7.k2dt4gfbmimux58s --discovery-token-ca-cert-hash sha256:84df1455ef7ae1dcc38dc9750754abe63b9360ca90e5ee88008240c458d43aeb

Make sure to run the commands in the output!

Install Calico for networking

kubectl apply -f https://docs.projectcalico.org/v3.1/getting-started/kubernetes/installation/hosted/rbac-kdd.yaml
kubectl apply -f https://docs.projectcalico.org/v3.1/getting-started/kubernetes/installation/hosted/kubernetes-datastore/calico-networking/1.7/calico.yaml

Check pods

$ kubectl get po -n kube-system
NAME                                    READY     STATUS    RESTARTS   AGE
calico-node-7jcn9                       2/2       Running   0          43s
coredns-78fcdf6894-khnzw                1/1       Running   0          5m
coredns-78fcdf6894-qt2kk                1/1       Running   0          5m
etcd-sko-demo-wbr1                      1/1       Running   0          5m
kube-apiserver-sko-demo-wbr1            1/1       Running   0          5m
kube-controller-manager-sko-demo-wbr1   1/1       Running   0          5m
kube-proxy-4fz5q                        1/1       Running   0          5m
kube-scheduler-sko-demo-wbr1            1/1       Running   0          4m

OPTIONAL: Untaint master node

For single node clusters, untaint the master node so that regular workloads can be scheduled.

 kubectl taint node <node-name> node-role.kubernetes.io/master-

Conclusion

For more info visit https://kubernetes.io/docs/setup/independent/create-cluster-kubeadm/#join-nodes

Restarting a Node

All Kubernetes components should automatically come back up. If not, make sure swap is still disabled and that the kubelet system service is running.

systemctl enable kubelet && systemctl start kubelet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment