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-podwith 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-podwithin the cluster. -
Service YAML Example:
-
Explanation: The
clusterip-web-serviceexposes theweb-app-podinside the cluster on TCP port 8081.
4. Exposing the Pod with a NodePort Service
- Objective: Expose the
web-app-podexternally, outside the Kubernetes cluster. -
Service YAML Example:
-
Explanation: The
nodeport-web-servicemakes the pod accessible externally on TCP port 30081 on each node in the cluster.
5. Verifying Service Exposure
- ClusterIP Verification: Use
kubectl execto access theweb-app-podfrom another pod within the cluster using the ClusterIP service. - NodePort Verification: Access the
web-app-podexternally using<NodeIP>:30081, whereNodeIPis 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.