Skip to Content
Asterrr's Handbook
Cheat sheets

Networking

Service types, DNS names, Ingress and Gateway API shapes, NetworkPolicy patterns and the ports to know.

Services

TypeReachNotes
ClusterIPIn-clusterDefault. A virtual IP held in kube-proxy rules
NodePort<node IP>:30000-32767Builds on ClusterIP
LoadBalancerExternal LBBuilds on NodePort. Needs a cloud controller or MetalLB
Headless (clusterIP: None)Pod IPs via DNSFor StatefulSets and peer discovery
ExternalNameCNAME to an outside nameNo proxying, no ports

port is the Service port, targetPort the Pod port, nodePort the node port. No endpoints means a selector or readiness problem. externalTrafficPolicy: Local keeps the client IP.

DNS names

NameResolves to
svc or svc.ns or svc.ns.svc.cluster.localThe Service ClusterIP
pod-0.svc.ns.svc.cluster.localA StatefulSet Pod behind a headless Service
10-42-1-14.ns.pod.cluster.localA Pod by IP (dashes)

A Pod's resolv.conf has search ns.svc.cluster.local svc.cluster.local cluster.local and options ndots:5. CoreDNS config is the ConfigMap coredns in kube-system, key Corefile.

Ingress and Gateway

kind: Ingress
spec:
  ingressClassName: nginx
  tls: [{ hosts: [shop.test], secretName: shop-tls }]
  rules:
  - host: shop.test
    http:
      paths:
      - { path: /cart, pathType: Prefix, backend: { service: { name: cart, port: { number: 80 } } } }
kind: HTTPRoute               # gateway.networking.k8s.io/v1
spec:
  parentRefs: [{ name: public-gw, namespace: gw-system }]
  hostnames: ["shop.test"]
  rules:
  - matches: [{ path: { type: PathPrefix, value: /cart } }]
    backendRefs: [{ name: cart-v1, port: 80, weight: 90 }, { name: cart-v2, port: 80, weight: 10 }]

NetworkPolicy patterns

GoalShape
Deny all ingresspodSelector: {} with policyTypes: [Ingress] and no rules
Deny all egresspodSelector: {} with policyTypes: [Egress] and no rules
Allow DNSEgress to the kube-system CoreDNS Pods on UDP and TCP 53
From a namespace and a Pod labelOne from element with both selectors (AND)
From eitherTwo from elements (OR)
Allow a CIDRipBlock: { cidr: 10.0.0.0/8, except: [10.0.1.0/24] }

Policies are additive allows. A Pod no policy selects stays open, and enforcement needs a CNI that supports it.

Ports

ComponentPort
kube-apiserver6443
etcd client, peer2379, 2380
kubelet10250
kube-scheduler, kube-controller-manager10259, 10257
kube-proxy health10256
NodePort range30000 to 32767
CoreDNS53 TCP and UDP

On this page