Run First WebApp in k8s cluster by kubeadm
First you need to make two instance
master node
worker node
Now install kubeadm by this link https://sarthakwrites.hashnode.dev/install-k8s-with-kubeadm-by-sarthak-tyagi
clone the repository in master node
git clone https://github.com/SarthakTyagiji/Color_Flipper.git
if it is private then use token access key
mkdir k8s
cd k8s
Write Menifest file for POD,DEPLOYMENT,SERVICE
Menifest file for Pod.yml
apiVersion: v1 #1st-4th line mostly similar
kind: Pod
metadata:
name: pod-file
spec: #This play a big role
containers:
- name: pod
image: tyagisarthak/color-app:latest
ports:
- containerPort: 80
imagePullPolicy: Always
Menifest file for Deployment.yml
Two thing is most important
selector and labels
In Template you define pod with a label and the same label define in selector and then by the selector service.yml will be selected the specific deployment.yml
pod>Deployment(template.lable -->selector.label)>service(selector)
Interconnected with each other Pod<-Deployment<-Service
In deployment mention pods and in service mention deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: app-deployment
labels: #this play a big role
app: webapp
spec:
replicas: 3
selector:
matchLabels: #it means selector should match the label from templete
app: webapp
template: #In this cointain pods and define label same label should be in selector
metadata:
labels:
app: webapp
spec:
containers:
- name: pod
image: tyagisarthak/color-app:latest
ports:
- containerPort: 80
imagePullPolicy: Always
Menifest file for Service.yml
apiVersion: v1
kind: Service
metadata:
name: service
spec:
selector:
app: webapp #make sure the same selector in deployment.yml
ports:
- protocol: TCP
port: 80 #Container internal port
targetPort: 80 #expose port outside the container
nodePort: 30007 #Public port access outside the cluster
type: NodePort