Kubernetes Setup with kubeadm

Steps

  • Create three linux machines with atleast 2 vcpu’s and 4gb ram in any environment
  • Login into the three machines and install docker using following instructions
# Install Docker CE
## Set up the repository:
### Install packages to allow apt to use a repository over HTTPS
apt-get update && apt-get install apt-transport-https ca-certificates curl software-properties-common

### Add Docker’s official GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -

### Add Docker apt repository.
add-apt-repository \
  "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) \
  stable"

## Install Docker CE.
apt-get update && apt-get install docker-ce=18.06.2~ce~3-0~ubuntu

# Setup daemon.
cat > /etc/docker/daemon.json <<EOF
{
  "exec-opts": ["native.cgroupdriver=systemd"],
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "100m"
  },
  "storage-driver": "overlay2"
}
EOF

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

# Restart docker.
systemctl daemon-reload
systemctl restart docker
  • Add the current user to the docker group and logout & login
sudo usermod -aG docker <yourusername>
  • Become root user
  • Install kubeadm, kubelet and kubectl on all the three nodes
apt-get update && apt-get install -y apt-transport-https curl
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 https://apt.kubernetes.io/ kubernetes-xenial main
EOF
apt-get update
apt-get install -y kubelet kubeadm kubectl
apt-mark hold kubelet kubeadm kubectl
  • Bootstrap the cluster on the master node using
kubeadm init --pod-network-cidr=10.244.0.0/16
  • make the note of join command printed out
  • Switch to non root user or exit from root
  • Setup kubeconfig using the following on the master
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
  • Login into the nodes and become root
  • Join the cluster using join command noted during kubeadm init execution
  • Login into the master and execute
kubectl get nodes
  • You will observe nodes in not ready state, So its time to setup cluster network. We will be using flannel, you can choose any from the kubernetes documentation
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/62e44c867a2846fefb68bd5f178daf4da3095ccb/Documentation/kube-flannel.yml
  • Execute kubectl get nodes -w you should see the nodes turing into ready state
  • Execute kubectl get pods -A and ensure all the pods are running
  • Setup Kubectl auto completion on master
source <(kubectl completion bash)
echo "source <(kubectl completion bash)" >> ~/.bashrc
  • Refer for kubectl command reference
  • Refer for kubectl cheatsheet

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About continuous learner

devops & cloud enthusiastic learner