Core Kubernetes · 08

Namespaces and Ingress

1.What is a Namespace ?

A scope for names. A name is unique inside its namespace, and the next namespace can reuse it.

  • No nesting. Each namespaced object lives in exactly one.
  • Name = RFC 1123 DNS label. The fixed label kubernetes.io/metadata.name is added for you.
  • Deleting one deletes all inside (phase Terminating): Pods first, then the rest.
  • Production : make your own, skip default.
Built inUsed for
defaultYour objects when you name no namespace
kube-systemObjects Kubernetes itself creates
kube-publicReadable by anyone, even anonymous. Mostly cluster use
kube-node-leaseOne Lease per node, the kubelet heartbeat for spotting dead nodes

The kube- prefix is reserved for system namespaces.

2.Names and policy, not traffic

Each of these is namespaced and acts only at home :

  • Role + RoleBinding : RBAC, here only
  • ResourceQuota : total cap, 403 if over
  • LimitRange : per Pod / Container limits
  • NetworkPolicy : traffic (section 4)
Not a firewallBy default any Pod reaches any Pod, in any namespace. Pod a1 calls api.team-b and nothing stops it.
Cluster ns team-a Pod a1 Role + RoleBinding ResourceQuota LimitRange ns team-b Service api forwards Pod b1 team-a's rules stop here api.team-b allowed Cluster-scoped, in no namespace Node, PersistentVolume, StorageClass, IngressClass, ClusterRole, Namespace

DNS crosses the line too. A Service is <svc>.<ns>.svc.cluster.local. A bare api only finds your own namespace's api (the search list starts there), so use api.team-b or the full name.

3.Namespaced or not ?

KindIn a ns ?Short
NamespaceNons
ResourceQuotaYesquota
LimitRangeYeslimits
Role / RoleBindingYesnone
ClusterRoleNonone
NetworkPolicyYesnetpol
IngressYesing
IngressClassNonone

apiVersion : v1 for the first three, rbac.authorization.k8s.io/v1 for RBAC, networking.k8s.io/v1 for the last three.

4.NetworkPolicy : the real wall

  • Namespaced L3/L4 allow-list for TCP, UDP, SCTP.
  • Pods start open. Once a policy selects a Pod for Ingress or Egress, only allowed traffic passes. Policies add up, no deny rules.
  • Both ends must agree : egress at the source and ingress at the target.
  • No policyTypes ? Ingress is implied. Egress only if it has egress rules.
  • Needs an enforcing network plugin (Antrea, Calico, Cilium, Kube-router, kind's kindnet). Without one it is stored and ignored, with no warning.
ns web frontend ns dev other ns prod api default-deny-ingress selects all Pods, no rules allow-from-web ingress from namespace web both select api allowed blocked times out or refused CNI plugin that enforces NetworkPolicy Calico, Cilium, Antrea, Kube-router, kindnet enforces
Gotchas
  • A policy cannot name a namespace. Match the label kubernetes.io/metadata.name=web.
  • In one from entry, namespaceSelector + podSelector mean AND. As two list items (two dashes) they mean OR.
  • Default-deny egress also blocks DNS. Allow the CoreDNS Pods.
  • Test a deny policy before you trust it.
In short : A namespace scopes names and the policy you attach (RBAC, ResourceQuota, LimitRange). It does not block traffic. That takes a NetworkPolicy and a CNI that enforces it.

1.Ingress : rules, not a proxy

An Ingress (networking.k8s.io/v1, namespaced) is just HTTP routing rules. A controller carries the traffic.

  • No controller ? Stored, does nothing.
  • HTTP / HTTPS only (80, 443). Else use a NodePort or LoadBalancer Service.
  • Backends : Services in its own namespace.
  • v1.37 : GA since v1.19, frozen. It stays, but the project recommends Gateway API.
Client shop.example.com HTTPS :443 Load balancer / edge set up by the controller Ingress controller proxy Pods /api / Service api Service web Pods API server config only, no traffic IngressClass spec.controller ingressClassName Ingress shop host + path rules ns shop tls.secretName Secret shop-tls kubernetes.io/tls backends : same ns reads

2.Inside an Ingress

One host, two paths, TLS
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata: {name: shop, namespace: shop}
spec:
  ingressClassName: example-class
  tls:                         # hosts = rule hosts
  - {hosts: [shop.example.com], secretName: shop-tls}
  rules:
  - host: shop.example.com
    http:
      paths:
      - path: /api
        pathType: Prefix     # required
        backend:
          service: {name: api, port: {number: 8080}}
      - path: /
        pathType: Prefix
        backend:           # port: number OR name
          service: {name: web, port: {name: http}}

Host first (exact, or *.foo.com = one label), then the longest path, Exact winning ties. No match : spec.defaultBackend, else the controller decides.

TypePathRequestMatch ?
Exact/foo/foo/no
Prefix/foo/bar/foo/bar/bazyes
Prefix/foo/bar/foo/barbazno, whole parts
Prefix/foo/bar//foo/baryes
ImplementationSpecific : up to the IngressClass
  • TLS ends at the LB or controller, plain text after. Port 443 only, hosts share it by SNI.
  • Secret type kubernetes.io/tls (tls.crt, tls.key). A rule with no host gets no TLS. Certs : cert-manager.

3.Picking a controller

IngressClass
  • Cluster-scoped. spec.controller (domain-prefixed, immutable) names the controller.
  • Default : ingressclass.kubernetes.io/is-default-class: "true". Two defaults = class-less Ingresses rejected.
  • kubernetes.io/ingress.class annotation : deprecated.
ingress-nginx is retired
  • Last releases 2026-03-19, archived 2026-03-24. No more fixes, not even security. Installs keep running.
  • Not F5's NGINX Ingress. nginx.ingress.kubernetes.io/* annotations don't carry over.
  • Way out : Gateway API (ingress2gateway 1.0 converts) or another controller.

4.Commands

CommandWhat it tells you
kubectl get ingressclassClasses and their controllers
kubectl get ing -AEmpty ADDRESS = no controller took it (yet)
kubectl describe ingress shop -n shopRules, backends with endpoints, events
kubectl create ingress shop --rule="shop.example.com/api*=api:8080" --dry-run=client -o yamlDraft YAML. Trailing * = Prefix, else Exact
kubectl create secret tls shop-tls -n shop --cert=tls.crt --key=tls.keyThe Secret for spec.tls
kubectl get pods -A --selector app.kubernetes.io/name=ingress-nginxStill running the retired controller ?
In short : An Ingress is HTTP routing config, and a controller does the work. The API is frozen and ingress-nginx is retired, so start new setups on Gateway API.