Deploy Kubernetes in Ubuntu 18.04 (Bionic Beaver)

$ sudo apt-get update
$ sudo apt-get install -y docker.io 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 https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add
$ sudo apt-add-repository "deb http://apt.kubernetes.io/ 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=10.244.0.0/16
$ 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 https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.ymlIf you want to use calico instead of flannel:
$ kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml
$ kubectl get pods --all-namespaces
$ kubectl get nodes
Following command will enable master node also to bring up the pods$ kubectl taint nodes --all node-role.kubernetes.io/master-
Create deployment.yaml$ vi ngin-deployment.yamlapiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- 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
--name=nginx-web-server
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 node-role.kubernetes.io/master-
To update the hostnamesudo vi /etc/hosts
127.0.1.1 <old hostname> <new hostname>
sudo hostnamectl set-hostname <new hostname>
Exit the vm and ssh again
Error: "The connection to the server 10.0.2.15:6443 was refused - did you specify the right host or port?"sudo -i
swapoff -a
exit
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