Services with YAML¶
Step-01: Introduction to Services¶
- We are going to look in to below two services in detail with a frotnend and backend example
- NodePort Service
- ClusterIP Service
Kubernetes Manifests¶
apiVersion: apps/v1
kind: Deployment
metadata:
name: backend-restapp
labels:
app: backend-restapp
tier: backend
spec:
replicas: 3
selector:
matchLabels:
app: backend-restapp
template:
metadata:
labels:
app: backend-restapp
tier: backend
spec:
containers:
- name: backend-restapp
image: stacksimplify/kube-helloworld:1.0.0
ports:
- containerPort: 8080
apiVersion: v1
kind: Service
metadata:
name: my-backend-service ## VERY VERY IMPORTANT - NGINX PROXYPASS needs this name
labels:
app: backend-restapp
tier: backend
spec:
#type: Cluster IP is a default service
selector:
app: backend-restapp
ports:
- name: http
port: 8080 # ClusterIp Service Port
targetPort: 8080 # Container Port
apiVersion: apps/v1
kind: Deployment
metadata:
name: frontend-nginxapp
labels:
app: frontend-nginxapp
tier: frontend
spec:
replicas: 3
selector:
matchLabels:
app: frontend-nginxapp
template:
metadata:
labels:
app: frontend-nginxapp
tier: frontend
spec:
containers:
- name: frontend-nginxapp
image: stacksimplify/kube-frontend-nginx:1.0.0
ports:
- containerPort: 80
Step-02: Create Backend Deployment & Cluster IP Service¶
- Write the Deployment template for backend REST application.
- Write the Cluster IP service template for backend REST application.
- Important Notes:
- Name of Cluster IP service should be
name: my-backend-servicebecause same is configured in frontend nginx reverse proxydefault.conf. - Test with different name and understand the issue we face
Step-03: Create Frontend Deployment & NodePort Service¶
- Write the Deployment template for frontend Nginx Application
- Write the NodePort service template for frontend Nginx Application
- Access REST Application
AWS EKS - Elastic Kubernetes Service - Masterclass¶
Step-04: Delete & Recreate Objects using kubectl apply¶
Delete Objects (file by file)¶
kubectl delete -f 01-backend-deployment.yml -f 02-backend-clusterip-service.yml -f 03-frontend-deployment.yml -f 04-frontend-nodeport-service.yml
kubectl get all
Recreate Objects using YAML files in a folder¶
cd <Course-Repo>\kubernetes-fundamentals\10-Services-with-YAML
kubectl apply -f kube-manifests/
kubectl get all
Delete Objects using YAML files in folder¶
cd <Course-Repo>\kubernetes-fundamentals\10-Services-with-YAML
kubectl delete -f kube-manifests/
kubectl get all
Additional References - Use Label Selectors for get and delete¶
- https://kubernetes.io/docs/concepts/cluster-administration/manage-deployment/#using-labels-effectively
- https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#label-selectors
🎉 New Course
Ultimate DevOps Real-World Project Implementation on AWS
$15.99
$84.99
81% OFF
APRIL2026
Enroll Now on Udemy
🎉 Offer
