-
STEP 1 — Create Deployment
Create a file apache-deployment.yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: apache-deploy
spec:
replicas: 2
selector:
matchLabels:
app: apache
template:
metadata:
labels:
app: apache
spec:
containers:
- name: apache
image: httpd:latest
ports:
- containerPort: 80
Apply the deployment:
kubectl apply -f apache-deployment.yaml
Check pods:
kubectl get pods
You should see 2 running Apache pods.
-
STEP 2 — Create ClusterIP Service
Create a file apache-service.yaml:
apiVersion: v1
kind: Service
metadata:
name: apache-service
spec:
selector:
app: apache
ports:
- protocol: TCP
port: 80
targetPort: 80
type: ClusterIP
Apply the service:
kubectl apply -f apache-service.yaml
Check the service:
kubectl get svc
You should see apache-service with a ClusterIP.
-
STEP 3 — Verify Inside the Cluster
Enter any pod (you can use one of the Apache pods or create a temporary pod):
kubectl run -it --rm debug-pod --image=curlimages/curl:latest --restart=Never -- sh
Inside the pod, test the service using curl:
curl http://apache-service
You should see the default Apache HTTP Server page HTML.
Exit the debug pod:
exit
-
STEP 4 — Test Using Port-Forwarding (Quickest for local testing)
kubectl port-forward service/apache-service 8088:80
This maps local port 8088 → service port 88.
Now open a browser and go to:
http://localhost:8088
You should see the Apache HTTP Server default page.