Deploy Kubernetes in Ubuntu 18.04 (Bionic Beaver)

$ sudo apt-get update
$ sudo apt-get install -y curl
$ sudo systemctl enable docker
$ sudo systemctl start docker
$ sudo groupadd docker
$ sudo usermod -aG docker $USER
$ sudo docker info
$ sudo sysctl net.bridge.bridge-nf-call-iptables=1
How to check Cgroup driver points to “systemd”$ sudo docker info | grep CgroupHow to change Cgroup driver to "systemd"$ sudo systemctl status docker
Check following section
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
$ sudo vi /lib/systemd/system/docker.service
Replace this line:
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
by:ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --exec-opt native.cgroupdriver=systemdRestart the Docker service by running the following command:$ sudo systemctl daemon-reload
$ sudo systemctl restart docker
Verify the cgroups driver to systemd$ sudo docker info | grep Cgroup
$ curl -s | sudo apt-key add
$ sudo apt-add-repository "deb kubernetes-xenial main"
$ sudo apt-get update
$ sudo apt-get install -y kubeadm kubelet kubectl
$ sudo apt-mark hold kubeadm kubelet kubectl
$ kubeadm version
$ sudo swapoff -a
$ sudo kubeadm init --pod-network-cidr=
$ mkdir -p $HOME/.kube
$ sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
$ sudo chown $(id -u):$(id -g) $HOME/.kube/config
$ kubectl apply -f you want to use calico instead of flannel:
$ kubectl apply -f
$ kubectl get pods --all-namespaces
$ kubectl get nodes
Following command will enable master node also to bring up the pods$ kubectl taint nodes --all
Create deployment.yaml$ vi ngin-deployment.yamlapiVersion: apps/v1
kind: Deployment
name: nginx-deployment
app: nginx
replicas: 3
app: nginx
app: nginx
- name: nginx
image: nginx:1.14.2
- containerPort: 80
Create deployment$ kubectl create -f ngin-deployment.yamlDeployment can be alternatively created using this command. $ kubectl create deployment nginx-dep --image=nginx:1.14.2 Later we can use following command to edit and update it$ kubectl get deployment nginx-dep -o yaml > dep.yamlCheck pods$ kubectl get podsCheck deployment$ kubectl get deploymentsCheck replicasets$ kubectl get replicasets
Create service$ kubectl expose deployment nginx-deployment --type=LoadBalancer
Check created services$ kubectl get servicesUse the <vm ip>:<node port> from above command to access nginx service from the host machine browser.
Reset the kubeadm$ sudo kubeadm reset
$ sudo rm -rf /var/lib/kubelet/pki
$ sudo swapoff -a
$ sudo sysctl net.bridge.bridge-nf-call-iptables=1
$ sudo rm -rf $HOME/.kube/config
$ kubectl taint nodes --all
To update the hostnamesudo vi /etc/hosts <old hostname> <new hostname>
sudo hostnamectl set-hostname <new hostname>
Exit the vm and ssh again
Error: "The connection to the server was refused - did you specify the right host or port?"sudo -i
swapoff -a
strace -eopenat kubectl version



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Prince Pereira

Prince Pereira

Software Engineer II - Microsoft | SDN | Java | Golang | DS & Algo | Microservices | Kubernetes | Docker | gRPC & Protocol Buffer