Cheat SheetsKubernetesNetworking

Networking — Cheat Sheet

Kubernetes · 1 topics. Download the PDF or the Instagram carousel and share it.

Cheat Sheet · AiCanCode.org
Networking
Kubernetes1 topicsQuick revision reference
1

Services & Networking

A Kubernetes Service provides a stable DNS name and IP for a set of pods. ClusterIP for internal, NodePort for development, LoadBalancer for production external traffic, and Ingress for HTTP routing.

  • Services provide stable DNS names for ephemeral pods — ClusterIP for internal, LoadBalancer for external.
  • Service selector labels must exactly match pod labels — mismatched labels = no traffic.
  • Ingress routes HTTP/HTTPS traffic by host and path — one external IP for multiple services.
  • CoreDNS auto-creates DNS records: service-name.namespace.svc.cluster.local.
  • kube-proxy maintains iptables/IPVS rules on each node to load-balance service traffic across pod IPs.
  • Headless services (clusterIP: None) return pod IPs directly via DNS — used by StatefulSets.
service.yaml — ClusterIP, LoadBalancer, NodePort
# ClusterIP (default) — internal only

apiVersion: v1

kind: Service

metadata:

  name: my-api

spec:

  type: ClusterIP             # accessible only within the cluster

  selector:

    app: my-api               # routes to pods with label app=my-api

  ports:

    - port: 80                # service port (what clients connect to)

      targetPort: 8080        # pod's containerPort



# DNS: my-api.default.svc.cluster.local:80

# Or within same namespace: my-api:80



---

# LoadBalancer — provisions cloud load balancer (GKE, EKS, AKS)

apiVersion: v1

kind: Service

metadata:

  name: my-api-external

spec:

  type: LoadBalancer

  selector:

    app: my-api

  ports:

    - port: 80

      targetPort: 8080

# After creation:

# kubectl get svc my-api-external

# NAME              TYPE          CLUSTER-IP    EXTERNAL-IP      PORT(S)

# my-api-external   LoadBalancer  10.96.24.51   34.102.145.100   80:32045/TCP

#                                               ↑ cloud LB IP (may take ~1 min)



---

# NodePort — exposes on each node's IP at a static port (30000-32767)

spec:

  type: NodePort

  selector:

    app: my-api

  ports:

    - port: 80

      targetPort: 8080

      nodePort: 31000         # access via: NodeIP:31000
Learn this free with Aria, your AI tutor → AiCanCode.org/learn/kubernetes