0
0
Kubernetesdevops~20 mins

NodePort service type in Kubernetes - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
NodePort Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Understanding NodePort Service Exposure

What is the primary purpose of a NodePort service in Kubernetes?

ATo expose a service on a static port on each node's IP, allowing external traffic to access the service.
BTo expose a service only via DNS inside the cluster.
CTo automatically assign a load balancer IP from a cloud provider.
DTo create an internal-only service accessible only within the cluster.
Attempts:
2 left
💡 Hint

Think about how external users can reach a service running inside Kubernetes nodes.

💻 Command Output
intermediate
1:00remaining
NodePort Service Port Range

What is the default port range for NodePort services in Kubernetes?

A80-8080
B1024-65535
C1-1023
D30000-32767
Attempts:
2 left
💡 Hint

NodePort ports are usually in a high range to avoid conflicts with well-known ports.

Configuration
advanced
2:30remaining
Correct NodePort Service YAML

Which YAML snippet correctly defines a NodePort service exposing port 8080 on target pods?

A
apiVersion: v1
kind: Service
metadata:
  name: my-nodeport-service
spec:
  type: NodePort
  selector:
    app: myapp
  ports:
    - port: 8080
      targetPort: 8080
      nodePort: 30080
B
apiVersion: v1
kind: Service
metadata:
  name: my-nodeport-service
spec:
  type: ClusterIP
  selector:
    app: myapp
  ports:
    - port: 8080
      targetPort: 8080
      nodePort: 30080
C
apiVersion: v1
kind: Service
metadata:
  name: my-nodeport-service
spec:
  type: NodePort
  selector:
    app: myapp
  ports:
    - port: 80
      targetPort: 8080
      nodePort: 30080
D
apiVersion: v1
kind: Service
metadata:
  name: my-nodeport-service
spec:
  type: NodePort
  selector:
    app: myapp
  ports:
    - port: 8080
      targetPort: 80
      nodePort: 30080
Attempts:
2 left
💡 Hint

Check that the service type is NodePort and ports match the target pod port.

Troubleshoot
advanced
2:00remaining
NodePort Service Not Accessible Externally

You created a NodePort service on port 30080, but external clients cannot access it. Which is the most likely cause?

AThe service type is incorrectly set to ClusterIP.
BThe cluster nodes' firewall is blocking port 30080.
CThe pod selector labels do not match any pods.
DThe nodePort value is outside the allowed range.
Attempts:
2 left
💡 Hint

Think about network rules outside Kubernetes that might block traffic.

Best Practice
expert
3:00remaining
Best Practice for NodePort Usage in Production

Which practice is recommended when using NodePort services in a production Kubernetes environment?

AExpose NodePort services on all nodes without any firewall restrictions.
BAlways assign nodePort values below 1024 for better compatibility.
CUse NodePort only for development or testing; use LoadBalancer or Ingress for production traffic.
DUse NodePort services to expose database ports directly to the internet.
Attempts:
2 left
💡 Hint

Consider security and scalability for production environments.