Skip to content

Network

Services, Ingress, and Ingress Gateway for Kubernetes networking

Overview

Kubernetes networking enables communication between Pods, Services, and external traffic. This section covers Services, Ingress, and Ingress Gateway.

Study Path

  1. Services - ClusterIP, NodePort, LoadBalancer
  2. Service Discovery - DNS and environment variables
  3. Ingress - HTTP/HTTPS routing
  4. Ingress Gateway - Advanced API Gateway patterns

Quick Comparison

TypeScopeUse Case
ClusterIPCluster internalInternal microservice communication
NodePortNode-level accessDevelopment, testing
LoadBalancerExternal accessProduction external access
IngressHTTP/HTTPS routingHost/path-based routing
Ingress GatewayAdvanced routingAPI Gateway, rate limiting, auth

Quick Reference

Common Commands

bash
# Services
kubectl get services
kubectl expose deployment nginx --port=80
kubectl describe service nginx

# Ingress
kubectl get ingress
kubectl describe ingress my-ingress

# Service discovery
kubectl run test --image=busybox -it -- wget http://service-name

Service Types

yaml
# ClusterIP (default)
apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  type: ClusterIP
  selector:
    app: nginx
  ports:
  - port: 80
    targetPort: 8080

---
# NodePort
apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  type: NodePort
  selector:
    app: nginx
  ports:
  - port: 80
    targetPort: 8080
    nodePort: 30080

---
# LoadBalancer
apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  type: LoadBalancer
  selector:
    app: nginx
  ports:
  - port: 80
    targetPort: 8080

Ingress Example

yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: my-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - host: example.com
    http:
      paths:
      - path: /app
        pathType: Prefix
        backend:
          service:
            name: app-service
            port:
              number: 80

Best Practices

  1. Use ClusterIP for internal services
  2. Use Ingress for external HTTP/HTTPS access
  3. Configure health checks on Services
  4. Use NetworkPolicies for security
  5. Implement proper TLS termination

Next Steps

  1. Learn Services: Services
  2. Understand Ingress: Ingress
  3. Practice: Lab 03: Services & Networking

Continue Learning:

Practice: Lab 03: Services

Return to: Key Concepts | Overview

Released under the MIT License.