Kubernetes Services with Pod Creation

1. Introduction to Kubernetes Services
- Purpose: Kubernetes Services allow for the exposure of applications running on Pods, both within the cluster and externally.
- Types of Services: Includes ClusterIP for internal exposure and NodePort for external exposure.
2. Creating a Sample Application Pod
- Objective: Deploy a simple web application pod to demonstrate service exposure.
-
Pod YAML Example:
-
Explanation: This creates a pod named
web-app-pod
with an Nginx container, labeledapp: web-app
, which we will expose using Services.
3. Exposing the Pod with a ClusterIP Service
- Objective: Expose the
web-app-pod
within the cluster. -
Service YAML Example:
-
Explanation: The
clusterip-web-service
exposes theweb-app-pod
inside the cluster on TCP port 8081.
4. Exposing the Pod with a NodePort Service
- Objective: Expose the
web-app-pod
externally, outside the Kubernetes cluster. -
Service YAML Example:
-
Explanation: The
nodeport-web-service
makes the pod accessible externally on TCP port 30081 on each node in the cluster.
5. Verifying Service Exposure
- ClusterIP Verification: Use
kubectl exec
to access theweb-app-pod
from another pod within the cluster using the ClusterIP service. - NodePort Verification: Access the
web-app-pod
externally using<NodeIP>:30081
, whereNodeIP
is the IP address of any node in the cluster.
6. Summary
- Effective Use of Services: Understanding how to expose pods using ClusterIP and NodePort services is essential for application accessibility in Kubernetes.