DevOps Certification Training Course
- 182k Enrolled Learners
- Weekend/Weekday
- Live Class
The first step toward Kubernetes Training Course is installing Kubernetes. This blog is a step-by-step guide to installing Kubernetes on top of Ubuntu VMs (Virtual Machines). Here, one VM will act as the master, and the other VM will be the node. You can then replicate the same steps to deploy the Kubernetes cluster onto your prod.
Note: For this installation, we recommend a fresh Ubuntu 16.04 image since Kubernetes can take up a lot of resources. If your installation fails at any time, execute all the steps mentioned from the beginning in a fresh VM because debugging would take longer.
To install Kubernetes, you have to diligently follow the 3 phases that come as part of the installation process:
This Edureka Kubernetes Full Course video will help you understand and learn the fundamentals of Kubernetes. This Kubernetes Tutorial is ideal for both beginners as well as professionals who want to master the fundamentals of Kubernetes.
Since we are dealing with VMs, we recommend the following settings for the VMs:-
Master:
Slave/ Node:
By this point of time, I have assumed you have 2 plain Ubuntu VMs imported onto your Oracle Virtual Box. So, I’l just get along with the installation process.
The following steps have to be executed on both the master and node machines. Let’s call the master ‘kmaster‘ and node as ‘knode‘.
First, login as ‘sudo’ user because the following set of commands need to be executed with ‘sudo’ permissions. Then, update your ‘apt-get’ repository.
$ sudo su # apt-get update
Note: After logging-in as ‘sudo’ user, note that your shell symbol will change to ‘#’ from ‘$’.
Next, we have to turn off the swap space because Kubernetes will start throwing random errors otherwise. After that you need to open the ‘fstab’ file and comment out the line which has mention of swap partition.
# swapoff -a # nano /etc/fstab
Then press ‘Ctrl+X’, then press ‘Y’ and then press ‘Enter’ to Save the file.
To change the hostname of both machines, run the below command to open the file and subsequently rename the master machine to ‘kmaster’ and your node machine to ‘knode’.
# nano /etc/hostname
Then press ‘Ctrl+X’, then press ‘Y’ and then press ‘Enter’ to Save the file.
Run the following command on both machines to note the IP addresses of each.
# ifconfig
Make a note of the IP address from the output of the above command. The IP address which has to be copied should be under “enp0s8”, as shown in the screenshot below.
Now go to the ‘hosts’ file on both the master and node and add an entry specifying their respective IP addresses along with their names ‘kmaster’ and ‘knode’. This is used for referencing them in the cluster. It should look like the below screenshot on both the machines.
# nano /etc/hosts
Then press ‘Ctrl+X’, then press ‘Y’ and then press ‘Enter’ to Save the file.
Next, we will make the IP addresses used above, static for the VMs. We can do that by modifying the network interfaces file. Run the following command to open the file:
# nano /etc/network/interfaces
Now enter the following lines in the file.
auto enp0s8
iface enp0s8 inet static
address <IP-Address-Of-VM>
It will look something like the below screenshot.
Then press ‘Ctrl+X’, then press ‘Y’ and then press ‘Enter’ to Save the file.
After this, restart your machine(s).
Now we have to install openshh-server. Run the following command:
# sudo apt-get install openssh-server
Now we have to install Docker because Docker images will be used for managing the containers in the cluster. Run the following commands:
# sudo su
# apt-get update
# apt-get install -y docker.io
Next we have to install these 3 essential components for setting up Kubernetes environment: kubeadm, kubectl, and kubelet.
Run the following commands before installing the Kubernetes environment.
# apt-get update && apt-get install -y apt-transport-https curl # 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
Now its time to install the 3 essential components. Kubelet is the lowest level component in Kubernetes. It’s responsible for what’s running on an individual machine. Kuebadm is used for administrating the Kubernetes cluster. Kubectl is used for controlling the configurations on various nodes inside the cluster.
# apt-get install -y kubelet kubeadm kubectl
Next, we will change the configuration file of Kubernetes. Run the following command:
# nano /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
This will open a text editor, enter the following line after the last “Environment Variable”:
Environment=”cgroup-driver=systemd/cgroup-driver=cgroupfs”
Now press Ctrl+X, then press Y, and then press Enter to Save.
Voila! You have successfully installed Kubernetes on both the machines now!
As of now, only the Kubernetes environment has been setup. But now, it is time to install Kubernetes completely, by moving onto the next 2 phases, where we will individually set the configurations in both machines.
Note: These steps will only be executed on the master node (kmaster VM).
Step 1: We will now start our Kubernetes cluster from the master’s machine. Run the following command:
# kubeadm init --apiserver-advertise-address=<ip-address-of-kmaster-vm> --pod-network-cidr=192.168.0.0/16
Step 2: As mentioned before, run the commands from the above output as a non-root user
$ mkdir -p $HOME/.kube
$ sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
$ sudo chown $(id -u):$(id -g) $HOME/.kube/config
It should look like this:
To verify, if kubectl is working or not, run the following command:
$ kubectl get pods -o wide --all-namespaces
Step 3: You will notice from the previous command, that all the pods are running except one: ‘kube-dns’. For resolving this we will install a pod network. To install the CALICO pod network, run the following command:
$ kubectl apply -f https://docs.projectcalico.org/v3.0/getting-started/kubernetes/installation/hosted/kubeadm/1.7/calico.yaml
After some time, you will notice that all pods shift to the running state
Step 4: Next, we will install the dashboard. To install the Dashboard, run the following command:
$ kubectl create -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml
It will look something like this:
Step 5: Your dashboard is now ready with it’s the pod in the running state.
Step 6: By default dashboard will not be visible on the Master VM. Run the following command in the command line:
$ kubectl proxy
Then you will get something like this:
To view the dashboard in the browser, navigate to the following address in the browser of your Master VM: http://localhost:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/
You will then be prompted with this page, to enter the credentials:
Step 7: In this step, we will create the service account for the dashboard and get it’s credentials.
Note: Run all these commands in a new terminal, or your kubectl proxy command will stop.
Run the following commands:
1. This command will create a service account for dashboard in the default namespace
$ kubectl create serviceaccount dashboard -n default
2. This command will add the cluster binding rules to your dashboard account
$ kubectl create clusterrolebinding dashboard-admin -n default
--clusterrole=cluster-admin
--serviceaccount=default:dashboard
3. This command will give you the token required for your dashboard login
$ kubectl get secret $(kubectl get serviceaccount dashboard -o jsonpath="{.secrets[0].name}") -o jsonpath="{.data.token}" | base64 --decode
You should get the token like this:
4. Copy this token and paste it in Dashboard Login Page, by selecting token option
5. You have successfully logged into your dashboard!
It is time to get your node, to join the cluster! This is probably the only step that you will be doing on the node, after installing kubernetes on it.
Run the join command that you saved, when you ran ‘kubeadm init’ command on the master.
Note: Run this command with “sudo”.
sudo kubeadm join --apiserver-advertise-address=<ip-address-of-the master> --pod-network-cidr=192.168.0.0/16
Bingo! Your Kubernetes Cluster is ready if you get something similar to the above screenshot.
So that brings an end to this blog on how to install Kubernetes on Ubuntu 16.04. Do look out for other blogs in this series that will explain the various other aspects of Kubernetes, or join our Kubernetes Training in Denver
Course Name | Date | Details |
---|---|---|
Kubernetes Certification Training Course: Administrator (CKA) | Class Starts on 22nd February,2025 22nd February SAT&SUN (Weekend Batch) | View Details |
edureka.co
repair actual link
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v1.10.1/src/deploy/recommended/kubernetes-dashboard.yaml
Hello, I have asked a question here, with respect to this blog: https://www.edureka.co/community/40930/kubernetes-dashboard-not-showing-up-outside
Can you please help me.?
I got below error while installing the kubernetes dashboard.
ubuntu@ubuntu:~$ kubectl create -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml
error: unable to read URL “https://raw.githubusercontent.com/kuberied toznetes/dashboard/master/src/deploy/rengcommended/kubernetes-dashboard.yaml”, server reported 404 Not Found, status code=404
Even i tried to access direct yaml file i am getting page not reachable.
https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml
Hi all,
After kubeadm init I got pods in pending state. I run “
kubectl apply -f ...calico.yaml
” and then its pod is also stuck in pending.I checked my nodes, and they are in NotReady state, the describe says something like:
“
Ready False ... ... KubeletNotReady runtime network not ready: NetworkReady=false reason:NetworkPluginNotReady message:docker: network plugin is not ready: cni config uninitialized
”Although I run “
kubectl apply ..calico
“, see above.Note: i’m using 2 network interfaces on my nodes, one for the whole local network (10.X.X.X ips), and one for my kubernetes cluster (192.168.1.X ips, via vlan.)
Could you help or give some tips please?
PS.: I tried run as single node cluster “
kubectl taint nodes --all node-role.kubernetes.io/master-
“, but it neither workskube-system kubernetes-dashboard-57df4db6b-2mbr5 0/1 ImagePullBackOff 0 127m 192.168.189.23 kmaster
I am getting this above error cause of which I am unable to access the dashboard and also rest of the modules are in “Running” state. What can be issue and the resolution methods ?
Thanks!
Balaji
Hii.
I was able to setup the master perfrctly, but when running the join command on node, I get error:
[preflight] Running pre-flight checks
[discovery] Trying to connect to API Server “172.31.44.167:6443”
[discovery] Created cluster-info discovery client, requesting info from “https://172.31.44.167:6443”
[discovery] Failed to request cluster info, will try again: [Get https://172.31.44.167:6443/api/v1/namespaces/kube-public/configmaps/cluster-info: dial tcp 172.31.44.167:6443: i/o timeout]
[discovery] Failed to request cluster info, will try again: [Get https://172.31.44.167:6443/api/v1/namespaces/kube-public/configmaps/cluster-info: dial tcp 172.31.44.167:6443: i/o timeout]
I want to create a two node cluster. One will be a worker node and other will be both i.e. master and worker (if possible, just master otherwise). I’ve two AWS EC2 ubuntu instances.
You said one needs to import those 2 plain ubuntu VMs to Oracle Virtualbox. How do we do that? I mean, how to import those into virtualbox. Sorry, I do know much of these, novice here.
Any help is appreciated.
Here is a near perfect solution: https://github.com/justmeandopensource/kubernetes/tree/master/vagrant-provisioning and the video that goes with it: https://www.youtube.com/watch?v=wPdIBeWJJsg.
Download Virtualbox and install. Download Vagrant then install. Run git clone on the repository, cd down to kubernetes/vagrant-provisioning then run vagrant up. Watch the video for details.
After running kadm init command
when i do kubectl get pods -o wide –all-namespace
I am getting 2 pods coming in pending state
root@kmaster:/home/amank-master# kubectl get pods -o wide –all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
kube-system coredns-86c58d9df4-ctxtz 0/1 Pending 0 2m43s
kube-system coredns-86c58d9df4-m88fx 0/1 Pending 0 2m43s
kube-system etcd-kmaster 1/1 Running 0 2m10s 192.168.33.105 kmaster
kube-system kube-apiserver-kmaster 1/1 Running 0 2m7s 192.168.33.105 kmaster
kube-system kube-controller-manager-kmaster 1/1 Running 0 2m2s 192.168.33.105 kmaster
kube-system kube-proxy-vmqz4 1/1 Running 0 2m43s 192.168.33.105 kmaster
kube-system kube-scheduler-kmaster 1/1 Running 0 118s 192.168.33.105 kmaster
Later on trying to run kubectl apply -f https://docs.projectcalico.org/v3.0/getting-started/kubernetes/installation/hosted/kubeadm/1.7/calico.yaml both coredns as well as calico pods are coming as pending
root@kmaster:/home/amank-master# kubectl get pods -n kube-system
NAME READY STATUS RESTARTS AGE
calico-kube-controllers-694687c474-jmzhw 0/1 Pending 0 3m19s
coredns-86c58d9df4-hjkwz 0/1 Pending 0 4m48s
coredns-86c58d9df4-rkhw6 0/1 Pending 0 4m48s
etcd-kmaster 1/1 Running 0 3m54s
kube-apiserver-kmaster 1/1 Running 0 4m13s
kube-controller-manager-kmaster 1/1 Running 0 3m57s
kube-proxy-fr42c 1/1 Running 0 4m49s
kube-scheduler-kmaster 1/1 Running 0 4m14s
can anyone suggest something for this?