Keyboard Shortcuts N Next post
P Previous post
S Save / unsave
R Read aloud
T Toggle theme
/ Focus search
Esc Close panels
🔥
Ready to read...
K8s Networking Kubernetes Kubernetes: From Zero to Production Module 4 - Services and Networking

Kubernetes Services Explained - ClusterIP, NodePort, LoadBalancer

Reviewed & accurate
AI Summary

What You Will Learn

Beginner

  • What a Service is and why Pods need it
  • The three Service types
  • How to create Services
Kubernetes Service TypesClusterIPInternal onlyDefault typeBest: internal svcNodePortNode IP + port30000-32767Best: dev/testingLoadBalancerCloud LBExternal IPBest: productionIngressHTTP routingDomain-basedBest: web appsAll service types provide a stable IP and DNS name for PodsPods die and get recreated; Services provide stable endpointsService = stable identity for a set of Pods
Four service types: ClusterIP (internal), NodePort (node), LoadBalancer (cloud), Ingress (HTTP)

A Service provides a stable IP and DNS name for a set of Pods. Pods come and go (new IPs), but the Service IP stays the same. Clients talk to the Service, which routes to healthy Pods.

service.yamlyaml
apiVersion: v1
kind: Service
metadata:
  name: my-app
spec:
  type: ClusterIP         # Default: internal only
  selector:
    app: my-app           # Routes to Pods with this label
  ports:
  - port: 80              # Service port
    targetPort: 8080       # Container port

Service Types

TypeAccessUse case
ClusterIPInternal only (default)Internal services (API to DB)
NodePortNodeIP:30000+Dev/testing
LoadBalancerCloud LB + external IPProduction (web apps)
IngressHTTP routing by domainMultiple web apps on one IP
Terminalbash
# Create a Service
kubectl apply -f service.yaml

# Check Services
kubectl get services

# Access ClusterIP internally
kubectl exec -it another-pod -- curl http://my-app

# NodePort access
minikube service my-app --url

Practical Exercise

Create a Deployment with label app=web
Create a ClusterIP Service matching that label
Check: kubectl get svc
Access: kubectl exec -it busybox -- curl http://my-app
Change to NodePort and access via minikube

Key Takeaways

  • Service = stable IP + DNS for a set of Pods.
  • ClusterIP: internal. NodePort: node port. LoadBalancer: cloud LB.
  • Selector matches Pod labels to route traffic.
  • Pods die and get new IPs - Service IP is stable.
  • DNS: my-service.namespace.svc.cluster.local
Previously: Module 3 covered workloads.
Today: You learned: Stable networking for Pods.
Next: Lesson 21 covers Ingress.
Test Your Knowledge
How did you find this?

Comments

Join the discussion! Sign in with your Google or Blogger account, or comment as Anonymous - no account needed. For quick questions, also reach me on Telegram @cytestch.

Comments