Skip to content

Instantly share code, notes, and snippets.

@steebchen
Last active May 21, 2019 21:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steebchen/786cd84d8b8316f13251bc2638d7bc24 to your computer and use it in GitHub Desktop.
Save steebchen/786cd84d8b8316f13251bc2638d7bc24 to your computer and use it in GitHub Desktop.
Kubernetes on Ubuntu
#!/bin/sh
# run this on all nodes
apt-get update && apt-get install -qy docker.io
apt-get update && apt-get install -y apt-transport-https \
&& curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" > /etc/apt/sources.list.d/kubernetes.list
apt-get update && apt-get install -y kubelet kubeadm kubernetes-cni
# pre-pull images on master so they're ready when we initialize the cluster
# kubeadm config images pull
#!/bin/sh
# run this on all nodes
apt-get update && apt-get install -qy --allow-downgrades docker.io=18.06.1-0ubuntu1.2~16.04.1
apt-get update && apt-get install -y apt-transport-https \
&& curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" > /etc/apt/sources.list.d/kubernetes.list
apt-get update && apt-get install -y --allow-downgrades kubelet=1.13.0-00 kubeadm=1.13.0-00 kubernetes-cni=0.6.0-00
#!/bin/sh
# RUN THIS ON THE ADMIN NODE ONLY
# 10.244.0.0/16 is the flannel subnet
# advertise the correct local IP
sudo kubeadm init --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=YOUR_LOCAL_IP_GOES_HERE
# add a user called default, this is required by k8s
sudo useradd default -G sudo -m -s /bin/bash
# replace 'a' with your password
echo "default:a" | chpasswd
# use `su - default` to switch to user first
# make sure you can use sudo
# RUN THIS ON THE ADMIN NODE ONLY
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
sudo cp /etc/kubernetes/admin.conf $HOME/
sudo chown $(id -u):$(id -g) $HOME/admin.conf
# this variable is read by flannel in a sec
export KUBECONFIG=$HOME/admin.conf
echo "export KUBECONFIG=$HOME/admin.conf" | tee -a ~/.bashrc
# set up network
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/k8s-manifests/kube-flannel-rbac.yml
# now run this in the shell to get the cluster joining command for the other nodes
kubeadm token create --print-join-command
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment