Skip to content

Instantly share code, notes, and snippets.

@davistran86
Last active August 10, 2017 04:40
Show Gist options
  • Save davistran86/8ca1e49c11c6288880173ebc957ed377 to your computer and use it in GitHub Desktop.
Save davistran86/8ca1e49c11c6288880173ebc957ed377 to your computer and use it in GitHub Desktop.
Install kubernetes on Ubuntu 16.0 using kubeadm
#1. Edit /etc/hosts file. Do this on all Nodes (including master).
nano /etc/hosts
#Add the following
#<master_ip> <master_hostname>
#<node_ip> <node_name>
#Eg.
192.168.121.10 k8s_master
192.168.121.11 k8s_node1
192.168.121.12 k8s_node2
#Restart
init 6
#2. Install NTP to sync time between Nodes. Do this on all Nodes
#List timezone
timedatectl list-timezones
#Set desired timezone
timedatectl set-timezone Asia/Ho_Chi_Minh
apt-get update && apt-get install ntp
systemctl enable ntp
systemctl start ntp
#3.Install Docker, currently K8s only support Docker version 1.12
apt-get update && apt-get install -qy docker.io
#NOTE: for missing socat in ubuntu
add-apt-repository universe
apt-get update && apt-get install socat
#4. Install Kubernetes
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 -
cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb http://apt.kubernetes.io/ kubernetes-xenial main
EOF
apt-get update && apt-get install -y kubelet kubeadm kubernetes-cni
#NOTE: for missing socat in ubuntu
add-apt-repository universe
apt-get update && apt-get install socat
#5. Start Kubernetes using kubeadm
kubeadm init --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=<master_ip_address> --skip-preflight-checks --kubernetes-version stable-1.6
#Note the kubeadm join -token xxxx , this token is used to join node to master, can get this token later if forgot by using: kubectl token list
cp /etc/kubernetes/admin.conf $HOME/
chown $(id -u):$(id -g) $HOME/admin.conf
export KUBECONFIG=$HOME/admin.conf
echo "export KUBECONFIG=$HOME/admin.conf" | tee -a ~/.bashrc
#6.Apply pod network
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel-rbac.yml
#clusterrole "flannel" created
#clusterrolebinding "flannel" created
kubectl create -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
#serviceaccount "flannel" created
#configmap "kube-flannel-cfg" created
#daemonset "kube-flannel-ds" created
#7.Optional. If we want to run pod on master
kubectl taint nodes --all node-role.kubernetes.io/master-
#8.Check the systemm should be "running" for all pods
kubectl get all --namespace=kube-system
#9.Deploy dashboard
kubectl create -f https://git.io/kube-dashboard
#use NodePort to open dashboard to the world
kubectl edit svc kubernetes-dashboard -n kube-system
#navigate to Type: ClusterIP, change "ClusterIP" to "NodePort"
kubectl describe svc kubernetes-dashboard -n kube-system
#now we have the port, eg. 32778. Go to browser, type <master_ip_address>:<port>, eg. 192.168.121.10:32778
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment