Introduction
Services expose pods to the network, and Ingress manages external HTTP routing. Together, they form the networking layer of Kubernetes applications.
Service Types
# ClusterIP (internal only)
apiVersion: v1
kind: Service
metadata:
name: myapp-service
spec:
selector:
app: myapp
ports:
- port: 80
targetPort: 8080
---
# NodePort (external access via node IP)
apiVersion: v1
kind: Service
metadata:
name: myapp-nodeport
spec:
type: NodePort
selector:
app: myapp
ports:
- port: 80
targetPort: 8080
nodePort: 30080
Ingress
# Install Ingress Controller
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.8.2/deploy/static/provider/cloud/deploy.yaml
# Ingress resource
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: myapp-ingress
spec:
rules:
- host: example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: myapp-service
port:
number: 80
Summary
Services provide stable networking for pods. Use ClusterIP for internal communication, NodePort for direct access, and Ingress for HTTP routing with domain names.
YouTip