Installing Kubernetes on Bare Metal Server or Virtual machine via kubeadm
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 update
$ apt-get install -y docker.io
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 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 kubectl kubernetes-cni
Install kubelet kubeadm kubectl kubernetes-cni for CentOS/RHEL:
$ cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
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=10.244.0.0/16 --apiserver-advertise-address=172.20.0.10
--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:
http://kubernetes.io/docs/admin/addons/
You can now join any number of machines by running the following on each node
as root:
$ kubeadm join --token 7ed3b7.ae447f51edc87df2 172.20.0.10:6443 --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.
Now you can check nodes for kubernetes cluster
$ kubectl get nodes
NAME STATUS AGE VERSION
master1 Ready 26m v1.7.0
Node1 Ready 2m v1.7.0
Node2 Ready 2m v1.7.0
For checking which pods are running on kubernetes cluster
$ kubectl get pods --all-namespaces -o wide
NAMESPACE NAME READY STATUS RESTARTS AGE IP NODE
kube-system kube-apiserver-master 1/1 Running 0 3m 172.20.0.10 master1
kube-system kube-controller-manager-master 1/1 Running 0 3m 172.20.0.10 master1
kube-system kube-dns-3913472980-k9mt6 3/3 Running 0 4m 10.244.0.106 master
kube-system kube-flannel-ds-3hhjd 2/2 Running 0 1m 172.20.0.10 master1
kube-system kube-proxy-rzq3t 1/1 Running 0 4m 172.20.0.10 master1
kube-system kube-scheduler-master 1/1 Running 0 3m 172.20.0.10 master1
Kubernets cluster running..!!!!
For Installing kubernetes we required 4 packages to be installed on machine.
Install Docker for Ubuntu:
$ apt-get update
$ apt-get install -y docker.io
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 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 kubectl kubernetes-cni
Install kubelet kubeadm kubectl kubernetes-cni for CentOS/RHEL:
$ cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
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=10.244.0.0/16 --apiserver-advertise-address=172.20.0.10
--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:
http://kubernetes.io/docs/admin/addons/
You can now join any number of machines by running the following on each node
as root:
$ kubeadm join --token 7ed3b7.ae447f51edc87df2 172.20.0.10:6443 --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.
Now you can check nodes for kubernetes cluster
$ kubectl get nodes
NAME STATUS AGE VERSION
master1 Ready 26m v1.7.0
Node1 Ready 2m v1.7.0
Node2 Ready 2m v1.7.0
For checking which pods are running on kubernetes cluster
$ kubectl get pods --all-namespaces -o wide
NAMESPACE NAME READY STATUS RESTARTS AGE IP NODE
kube-system kube-apiserver-master 1/1 Running 0 3m 172.20.0.10 master1
kube-system kube-controller-manager-master 1/1 Running 0 3m 172.20.0.10 master1
kube-system kube-dns-3913472980-k9mt6 3/3 Running 0 4m 10.244.0.106 master
kube-system kube-flannel-ds-3hhjd 2/2 Running 0 1m 172.20.0.10 master1
kube-system kube-proxy-rzq3t 1/1 Running 0 4m 172.20.0.10 master1
kube-system kube-scheduler-master 1/1 Running 0 3m 172.20.0.10 master1
Kubernets cluster running..!!!!
Comments
Post a Comment