Installing Kubernetes on Bare Metal Server or Virtual machine via kubeadm

Sachin Arote
Nov 24, 2017 · 2 min read

Kubernetes is docker orchestration tool developed by google.

For Installing kubernetes we required 4 packages to be installed on machine.

Install Docker for Ubuntu:

$ apt-get install -y

Install Docker for CentOS/RHEL:

$ yum install -y docker$ systemctl enable docker && systemctl start docker

Install kubeadm, kubelet and kubectl.

kubeadm: The command to bootstrap the cluster.

kubelet: The component that runs on all of the machines in your cluster and does things like starting pods and containers.

kubectl: The command line util to talk to your cluster.

Install kubelet kubeadm kubectl kubernetes-cni for Ubuntu:

$ apt-get update && apt-get install -y apt-transport-https$ curl -s | apt-key add -$ cat <<EOF >/etc/apt/sources.list.d/kubernetes.listdeb kubernetes-xenial mainEOF$ apt-get update$ apt-get install -y kubelet kubeadm kubectl kubernetes-cni

Install kubelet kubeadm kubectl kubernetes-cni for CentOS/RHEL:

$ cat <<EOF > /etc/yum.repos.d/kubernetes.repo
EOF$ setenforce 0$ yum install -y kubelet kubeadm kubectl$ systemctl enable kubelet && systemctl start kubelet

Initializing cluster with kubeadm

On master node

$ kubeadm init — pod-network-cidr= — apiserver-advertise-address=

— apiserver-advertise-address determines which IP address Kubernetes should advertise its API server on.

You will get this when you done with Kubadm init.

Your Kubernetes master has initialized successfully!

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

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

as root:

$ kubeadm join — token 7ed3b7.ae447f51edc87df2 — discovery-token-ca-cert-hash sha256:7b19036bd9cfc7e4e09721448e0a0467cf7fc67c982abbf36f478e0c2eec32cb

Via this token you can connect new nodes to master.

For installing nodes you need to do all the steps as given above but only $kubeadm init not required.

$kubectl apply --filename

For running kube-dns POD’s

Now you can check nodes for kubernetes cluster

$ kubectl get nodes

For checking which pods are running on kubernetes cluster

$ kubectl get pod --all namespaces -o wide

Kubernets cluster running..!!!!


26 claps
Sachin Arote

Written by

Devops Engineer | Docker | AWS | CloudFormation | Spinnaker|Jenkins|Prometheus|Grafana | Kubernetes | ECS | GCE & GKE