0% found this document useful (0 votes)
421 views17 pages

Kubernets Aws PDF

Uploaded by

mangaya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
421 views17 pages

Kubernets Aws PDF

Uploaded by

mangaya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

DevOps Certification Training www.edureka.

co/devops

Kubernetes Installation Guide


Installation Notes

© Brain4ce Education Solutions Pvt. Ltd.


Module 10: Containerization Using Kubernetes www.edureka.co/devops

Connect to an EC2 instance(Ubuntu).

Steps for Master and Slave VMs


Note: These steps are common to both kmaster and knode VMs
Step 1:
1. Run the following commands:
sudo su
apt-get update
swapoff -a

Step 2:
1. Run the following command:
nano /etc/hostname

©Brain4ce Education Solutions Pvt. Ltd Page 1


Module 10: Containerization Using Kubernetes www.edureka.co/devops

2. Edit the name to “kmaster” for kmaster VM, and “knode” for knode VM

Step 3:

1. Run the following command


nano /etc/hosts

2. Enter the IP address of the kmaster VM and the knode VM both in this file. (This has to be
done in both the VMs). In front of the IP address of master write, “kmaster”. Similarly, in
front of the Node IP address write “knode”.

Step 4: Now we will ssh from one machine to another. Run the below command:
1. su - ubuntu
2. sudo service ufw stop
3. sudo service ssh start
4. eval `ssh-agent -s`
Note: Where ` in the above command refers to grave(`) and it is not a single quote(')
5. chmod 400 file_name.pem

©Brain4ce Education Solutions Pvt. Ltd Page 2


Module 10: Containerization Using Kubernetes www.edureka.co/devops

6. ssh-add file_name.pem
Note: The file_name.pem is the file which you have transferred using Filezilla software in the
first step.
7. ssh ubuntu@<private_IP_of_the_other_instance>

Step 5: Next, we will install Docker. Run the following commands:


sudo su
apt-get update
apt-get install -y docker.io

©Brain4ce Education Solutions Pvt. Ltd Page 3


Module 10: Containerization Using Kubernetes www.edureka.co/devops

Step 6: Next, we will install kubeadm, kubelet and kubectl. Run the following commands:
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

©Brain4ce Education Solutions Pvt. Ltd Page 4


Module 10: Containerization Using Kubernetes www.edureka.co/devops

apt-get install -y kubelet kubeadm kubectl

©Brain4ce Education Solutions Pvt. Ltd Page 5


Module 10: Containerization Using Kubernetes www.edureka.co/devops

Step 7:
1. Next, we will change the configuration file of Kubernetes. Run the following command:

nano /etc/systemd/system/kubelet.service.d/10-kubeadm.conf

2. This will open a text editor, enter the following line after the last “Environment” Variable.
Environment="cgroup-driver=systemd/cgroup-driver=cgroupfs"

Step 8: Restart your VMs for the changes to take effect.

You have successfully installed Kubernetes on both the machines now!

Steps for only Master VM

©Brain4ce Education Solutions Pvt. Ltd Page 6


Module 10: Containerization Using Kubernetes www.edureka.co/devops

Note: These steps will only be executed on the master node (kmaster VM).

Step 1: We will now Initialize our Master VM. For that execute the following command
kubeadm init --apiserver-advertise-address=<ip-address-of-kmaster-vm>

1. You will get the below output. The commands marked as (1), execute them as a non-root user. This will
enable you to use kubectl from the CLI

2. The command marked as (2) should also be saved for future. This will be used to join nodes to your
cluster.

Step 2:
1. Like mentioned before, run the commands from the above output as a nonroot user.

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config

©Brain4ce Education Solutions Pvt. Ltd Page 7


Module 10: Containerization Using Kubernetes www.edureka.co/devops

sudo chown $(id -u):$(id -g) $HOME/.kube/config

2. To verify, if kubectl is working or not, run the following command:

kubectl get pods -o wide --all-namespaces

Step 3:
1. You will notice from the previous command, all the pods are not running. For resolving this
we will install a pod network. To install the pod network, run the following command:

kubectl apply -f https://docs.projectcalico.org/v3.1/getting-


started/kubernetes/installation/hosted/rbac-kdd.yaml

kubectl apply -f https://docs.projectcalico.org/v3.1/getting-


started/kubernetes/installation/hosted/kubernetes-datastore/calico-networking/1.7/calico.yaml

©Brain4ce Education Solutions Pvt. Ltd Page 8


Module 10: Containerization Using Kubernetes www.edureka.co/devops

Step 4:
Next, we will install the dashboard. To install the Dashboard, run the following command:

©Brain4ce Education Solutions Pvt. Ltd Page 9


Module 10: Containerization Using Kubernetes www.edureka.co/devops

kubectl create -f
https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/k
ubernetes-dashboard.yaml

Step 5: Your dashboard is now ready with it’s the pod in the running state.

Step 6: Now list all the services

Step 7:
1. By default dashboard will not be visible on the Master VM. Run the following command in the
command line:

2. Curl the site

curl 127.0.0.1:8001

©Brain4ce Education Solutions Pvt. Ltd Page 10


Module 10: Containerization Using Kubernetes www.edureka.co/devops

3. Run the below command:

kubectl get svc --all-namespaces

4. Edit the file svc file for kubernetes dashboard using the below command and change the
type to NodePort.
kubectl edit svc kubernetes-dashboard –namespaces=kube-system

©Brain4ce Education Solutions Pvt. Ltd Page 11


Module 10: Containerization Using Kubernetes www.edureka.co/devops

5. Run the below command again:


Kubectl get svc –all-namespaces

You will get the port on which kubernetes dashboard is running as shown in the below
screenshot.

©Brain4ce Education Solutions Pvt. Ltd Page 12


Module 10: Containerization Using Kubernetes www.edureka.co/devops

6. To view the dashboard in the browser, navigate to the following address in the browser of
your Master VM and use mozilla firefox and any other browser other than chrome.

https://External_IP_of_Instance:Port_Number

7. You will prompted with this page, to enter the credentials.

Step 8: In this step, we will create the service account for the dashboard and get it’s
credentials. Run the following commands:

Note: Run all these commands in a new terminal, or your kubectl proxy command will stop.

1. This command will create 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.

©Brain4ce Education Solutions Pvt. Ltd Page 13


Module 10: Containerization Using Kubernetes www.edureka.co/devops

kubectl create serviceaccount dashboard -n default


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

4. Copy this token and paste it in Dashboard Login Page, by selecting token option.

5. You have successfully logged in your dashboard!

©Brain4ce Education Solutions Pvt. Ltd Page 14


Module 10: Containerization Using Kubernetes www.edureka.co/devops

Steps for only Node VM

Step 1: It is time to join your node to 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”.

©Brain4ce Education Solutions Pvt. Ltd Page 15


Module 10: Containerization Using Kubernetes www.edureka.co/devops

Your Kubernetes Cluster is ready!

©Brain4ce Education Solutions Pvt. Ltd Page 16

You might also like