0
0
Kubernetesdevops~30 mins

NodePort service type in Kubernetes - Mini Project: Build & Apply

Choose your learning style9 modes available
Create a Kubernetes NodePort Service
📖 Scenario: You have a simple web application running inside a Kubernetes cluster. You want to expose this application so that it can be accessed from outside the cluster on a specific port.
🎯 Goal: Learn how to create a Kubernetes NodePort service to expose a pod on a fixed port accessible from outside the cluster.
📋 What You'll Learn
Create a pod running the nginx image
Create a NodePort service exposing the pod on port 80 internally
Set the NodePort to 30080
Verify the service is created and accessible
💡 Why This Matters
🌍 Real World
NodePort services are used to expose applications running inside Kubernetes clusters to external clients by opening a port on each node.
💼 Career
Understanding how to expose services with NodePort is essential for DevOps engineers managing Kubernetes clusters and deploying applications accessible outside the cluster.
Progress0 / 4 steps
1
Create a pod running nginx
Create a YAML file named nginx-pod.yaml that defines a pod called nginx-pod running the nginx image with container port 80.
Kubernetes
Need a hint?

Use kind: Pod and specify containers with image: nginx and containerPort: 80. Add label app: nginx under metadata.

2
Create a NodePort service configuration
Create a YAML file named nginx-service.yaml that defines a service called nginx-service of type NodePort. It should select the pod with label app: nginx, expose port 80 internally, and use NodePort 30080.
Kubernetes
Need a hint?

Use kind: Service with type: NodePort. Set selector: app: nginx and ports with port: 80 and nodePort: 30080.

3
Apply the pod and service to the cluster
Use kubectl apply -f nginx-pod.yaml and kubectl apply -f nginx-service.yaml commands to create the pod and NodePort service in the cluster.
Kubernetes
Need a hint?

Use kubectl apply -f with the YAML filenames to create resources.

4
Check the NodePort service status
Run kubectl get service nginx-service and print the output to verify the service is created with the correct NodePort 30080.
Kubernetes
Need a hint?

Use kubectl get service nginx-service to see the service details including the NodePort.