Kubernetes services and CNI
Pods, nodes and CNI
Kubernetes schedules Pods, which may contain more than one container. Containers in an ordinary Pod share the network namespace, so a sidecar can contact its companion through localhost and cannot claim the same listening socket. Different Pods normally have distinct IP addresses. The cluster networking model expects Pod-to-Pod connectivity without requiring application-visible address translation. A Container Network Interface (CNI) plugin is invoked by a compatible runtime to attach or detach network connectivity according to its configuration. IP allocation, routes, encapsulation and policy vary with the implementation. CNI is an interface specification, not a single tunneling protocol. Our lab assumes Linux nodes, IPv4, a working routed Pod network and a policy-capable implementation; it excludes hostNetwork Pods.
Separate stable service identity from changing endpoints
An order API has two ready Pods at 10.53.10.21:8080 and 10.53.20.22:8080. Its Service in namespace shop has selector app=orders, ClusterIP 10.54.0.80 and TCP port 80 with targetPort 8080. A client connects to 10.54.0.80:80; the Service data plane selects an eligible backend and forwards toward its Pod IP and target port. For this simple example the reply is translated back to the Service connection identity by the connection-tracking data plane. kube-proxy can implement Service forwarding; some networking implementations replace it with another data plane such as eBPF. The API and EndpointSlices express desired connectivity and backend membership; they are not proof that packets pass. A recreated Pod may have a new IP; the Service remains the client-facing identity while that Service exists.
Choose the correct exposure layer
ClusterIP is intended for access within the cluster. NodePort additionally exposes a port on eligible node addresses, subject to configuration and policy. LoadBalancer asks a supported implementation to provide load-balancing access; it may be internal or external. An Ingress resource describes HTTP(S) routing and needs an Ingress controller. Gateway API is another resource family for configuring traffic handling with a compatible controller. Neither creates a functioning proxy by declaration alone. A service mesh may add application-level routing, workload identity, mutual TLS and telemetry, but requires its own setup and does not replace basic connectivity. In this chapter choose ClusterIP for the internal order API; exposing it directly to the Internet is not a requirement.
Trace the mock Service
Read the following mock manifest excerpt as data, not a command to apply. Assume no session affinity, ordinary ready endpoints and no special traffic policy. Both ready matching endpoints are eligible; the selection algorithm is not specified. If one becomes unready, the other remains eligible. If the selector is misspelled, neither matches; a DNS answer or Service IP still does not guarantee a backend. If the target port is wrong, eligible endpoints may be selected but the application connection fails. Start with selector, readiness, EndpointSlices, Service port and target port, then inspect node-to-Pod paths and policy. Verify application status and latency after reachability; avoid treating a single successful request as proof that both backends work.
apiVersion: v1kind: Servicemetadata: name: orders namespace: shopspec: type: ClusterIP clusterIP: 10.54.0.80 selector: app: orders ports: - port: 80 targetPort: 8080 protocol: TCPCheck Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Kubernetes services and CNI Quiz
Reason about namespaces, Service forwarding and network policy.
Two ordinary containers in one Pod need to listen on the same TCP address and port. What happens without special socket sharing?
Which backend port does the sample Service use?
One of two matching endpoints becomes unready. Under the stated assumptions what remains eligible?
Which Service type is appropriate for the internal example?
What does CNI specify?