Cheat sheets
Networking
Service types, DNS names, Ingress and Gateway API shapes, NetworkPolicy patterns and the ports to know.
Services
| Type | Reach | Notes |
|---|---|---|
| ClusterIP | In-cluster | Default. A virtual IP held in kube-proxy rules |
| NodePort | <node IP>:30000-32767 | Builds on ClusterIP |
| LoadBalancer | External LB | Builds on NodePort. Needs a cloud controller or MetalLB |
Headless (clusterIP: None) | Pod IPs via DNS | For StatefulSets and peer discovery |
| ExternalName | CNAME to an outside name | No 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
| Name | Resolves to |
|---|---|
svc or svc.ns or svc.ns.svc.cluster.local | The Service ClusterIP |
pod-0.svc.ns.svc.cluster.local | A StatefulSet Pod behind a headless Service |
10-42-1-14.ns.pod.cluster.local | A 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
| Goal | Shape |
|---|---|
| Deny all ingress | podSelector: {} with policyTypes: [Ingress] and no rules |
| Deny all egress | podSelector: {} with policyTypes: [Egress] and no rules |
| Allow DNS | Egress to the kube-system CoreDNS Pods on UDP and TCP 53 |
| From a namespace and a Pod label | One from element with both selectors (AND) |
| From either | Two from elements (OR) |
| Allow a CIDR | ipBlock: { 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
| Component | Port |
|---|---|
| kube-apiserver | 6443 |
| etcd client, peer | 2379, 2380 |
| kubelet | 10250 |
| kube-scheduler, kube-controller-manager | 10259, 10257 |
| kube-proxy health | 10256 |
| NodePort range | 30000 to 32767 |
| CoreDNS | 53 TCP and UDP |