Custom Search

Sunday, May 19, 2019

How to Install and Configure Kubernetes (k8s) on Ubuntu 18.04 LTS 19.04

1)
$ sudo apt update

#install docker
$ sudo apt-get install docker.io -y

$ sudo systemctl start docker
$ sudo systemctl enable docker

$ docker --version

2)

$ sudo apt-get install apt-transport-https curl -y

# add Kubernetes package repository key
$ curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add

# configure Kubernetes repository
$ sudo apt-add-repository "deb http://apt.kubernetes.io/ kubernetes-xenial main"

$ sudo apt update

3)
#disable swap temporary,
$ sudo swapoff -a

4)
$ Kubeadm is one of the most common method used to deploy kubernetes cluster

#Install Kubeadm package
$ sudo apt-get install kubeadm -y

$ kubeadm version

#install the parts we need for Kubernetes
$ sudo apt-get install -y kubelet kubectl kubernetes-cni

5)
Kubernetes requires a Pod Network for the pods to communicate. For this guide we will use Flannel although there are several other Pod Networks availabl

#We can now initialize Kubernetes by running the initialization command and passing --pod-network-cidr which is required for Flannel to work correctly
$ sudo kubeadm init --pod-network-cidr=172.168.10.0/24


$ mkdir -p $HOME/.kube
$ sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
$ sudo chown $(id -u):$(id -g) $HOME/.kube/config

#check status of node
$ kubectl get nodes

6)
Once Kubernetes has been initialized we then install the Flannel Pod Network by running.
Let’s deploy the pod network, Pod network is the network through which our cluster nodes will communicate with each other. We will deploy Flannel as our pod network, Flannel will provide the overlay network between cluster nodes.

First we need to set /proc/sys/net/bridge/bridge-nf-call-iptables to 1 to pass bridged IPv4 traffic to iptables` chains which is required by certain CNI networks (in this case Flannel). Do this by issueing

$ sudo sysctl net.bridge.bridge-nf-call-iptables=1

$ sudo kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

#We can check that the pod is up by running
$ kubectl get pods --all-namespaces

7)
$ sudo  kubectl get nodes

8)
Because we are running only a single Kubernetes node we want to be able to run Pods on the master node. To do this we need to untaint the master node so it can run regular pods. To do so run
$ kubectl taint nodes --all node-role.kubernetes.io/master-













5 comments:

  1. Thank you for the great notes. When i tried to add the nodes to master getting below error. Can you assist.?

    root@slave01:~# kubeadm join 192.168.1.6:6443 --token c8pr1u.1tnhr90lastm7rb9 --discovery-token-ca-cert-hash sha256:c419944b77b0218a2e31344cc90cc06ab218c9ff1b29b5e9c89ee5d34500c53d
    [preflight] Running pre-flight checks
    [WARNING IsDockerSystemdCheck]: detected "cgroupfs" as the Docker cgroup driver. The recommended driver is "systemd". Please follow the guide at https://kubernetes.io/docs/setup/cri/
    error execution phase preflight: [preflight] Some fatal errors occurred:
    [ERROR Port-10250]: Port 10250 is in use
    [preflight] If you know what you are doing, you can ma

    ReplyDelete
    Replies
    1. $ sudo kubeadm init --pod-network-cidr=172.168.10.0/24


      while executing this above command getting some fatal error plz give solution

      Delete
    2. You have to follow this to fix this error.
      https://kubernetes.io/docs/setup/production-environment/container-runtimes/#docker

      Delete
  2. Very helpful Blog. Pretty much informative. Thanks Much

    ReplyDelete