0% found this document useful (0 votes)
1 views

Commands Till Service

This document outlines the steps to set up a master and slave server for Kubernetes. It includes commands for configuring hostnames, installing necessary packages, initializing kubeadm on the master, and creating a deployment and service for an Nginx application. The final step involves accessing the service via a web browser using the server's public IP and assigned port.

Uploaded by

iamswazir7710
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

Commands Till Service

This document outlines the steps to set up a master and slave server for Kubernetes. It includes commands for configuring hostnames, installing necessary packages, initializing kubeadm on the master, and creating a deployment and service for an Nginx application. The final step involves accessing the service via a web browser using the server's public IP and assigned port.

Uploaded by

iamswazir7710
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Create two server with name master and slave :

Step1: On master instance we have to run these commands:


First set the hostname so that while doing the command there is no confusion that you are running
commands on which server master or slave.

$ sudo hostnamectl set-hostname master

$ bash

$ sudo su

$ sudo apt-get update && apt-get upgrade -y

After this reboot the system by using the command

$ sudo reboot -f

After reboot connect with the server again and run the following commands on Master server:

$ sudo su

$ apt-get update

$ apt-get install docker.io

$ 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 https://apt.kubernetes.io/ kubernetes-xenial main

EOF

# apt-get update

$ apt-get install -y kubelet kubeadm kubectl

Step 2: Now On Slave we have to run theses commands:


In this we also do the same thing, first set the hostname so that while doing the command there is
no confusion that you are running commands on which server master or slave.

$ sudo hostnamectl set-hostname slave

$ bash

$ sudo su

$ sudo apt-get update && apt-get upgrade -y

After this reboot the system by using the command

$ sudo reboot -f
After reboot connect with the server again and run the following commands on Slave server:

$ sudo su

$ apt-get update

$ apt-get install docker.io

$ 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 https://apt.kubernetes.io/ kubernetes-xenial main

EOF

$ apt-get update

$ apt-get install -y kubelet kubeadm kubectl


Step 3: Now on master we Initialize kubeadm using the following
command:
$ kubeadm init --apiserver-advertise-address=<master private ip address> --pod-network-
cidr=192.168.0.0/16 --ignore-preflight-errors=all

Copy Kubeadm join command from master to Slave

Now on slave terminal we have to paste kubeadm join command .


We have to paste this token from master to slave so that we connect both master and slave

Step 4 : Now on master we have to run the following


commands:
Exit from root user for that you have to write exit on your master terminal

After that perform these commands :

$ mkdir -p $HOME/.kube

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

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

$ curl https://raw.githubusercontent.com/projectcalico/calico/v3.26.1/manifests/calico.yaml -O
$ kubectl apply -f calico.yaml

$ kubectl get nodes


Step 5: Now create deployment file on master server
$ nano deployment.yml

Copy this script and paste it in your deployment file :

apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
spec:
strategy:
type: Recreate
selector:
matchLabels:
app: nginx
replicas: 3
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80

$ kubectl create -f deployment.yml


$ kubectl get po

Step 6: Now we will create service on Master server:


$ nano service.yml

Copy this script and paste it your service file

apiVersion: v1
kind: Service
metadata:
name: nginx
namespace: default
labels:
app: nginx
spec:
externalTrafficPolicy: Local
ports:
- name: http
port: 80
protocol: TCP
targetPort: 80
selector:
app: nginx
type: NodePort
$ kubectl create -f service.yml

$ kubectl get service |grep nginx

$ kubectl get service | grep nginx

In the above screenshot, it can be seen that the Service is available on Port 30950. This can
be different for you as the port is randomly assigned from the available range.
Now go on the browser and put public ip address of your master or slave whatever you want and
using colon put port number . for ex : Ipslave:30950

Here it is: 3.6.37.205:30950

You might also like