All exams← All Certified Kubernetes Administrator (CKA) notes

Services & Networking: Certified Kubernetes Administrator (CKA) revision notes

Revision notes

## Services

A Service is a Kubernetes object that defines a logical set of Pods and a policy by which to access them. Services provide a stable network endpoint (IP address and DNS name) for a dynamic set of Pods, which are often ephemeral. Services use label selectors to identify the Pods they target.

There are several Service Types:

  • ClusterIP: The default type. Exposes the Service on an internal IP address within the cluster. It's only reachable from inside the cluster.
  • NodePort: Exposes the Service on each Node's IP at a static port (the `NodePort`). This makes the Service accessible from outside the cluster via `<NodeIP>:<NodePort>`.
  • LoadBalancer: Exposes the Service externally using a cloud provider's load balancer. This type is only effective when running on a cloud provider that supports it.
  • ExternalName: Maps the Service to a DNS name by returning a `CNAME` record. No proxying is involved.

kube-proxy is a network proxy that runs on each node in the cluster, implementing the Service concept. It maintains network rules (e.g., iptables or IPVS) to forward traffic to the correct backend Pods. EndpointSlices are a more scalable and efficient way to track network endpoints for Services, especially in large clusters, replacing the older Endpoints resource.

## Ingress

Ingress is an API object that manages external access to services in a cluster, typically HTTP/HTTPS. It provides routing rules for traffic based on hostnames and paths to backend Services. An Ingress Controller is essential for Ingress resources to function; it's a specialized pod that watches the Ingress API and configures a load balancer or proxy accordingly (e.g., Nginx, HAProxy). Ingress can also be configured for TLS termination using Kubernetes Secrets.

## Network Policies

NetworkPolicy is an API object that allows you to specify how groups of Pods are allowed to communicate with each other and other network endpoints. By default, Pods are non-isolated, meaning they can communicate freely. Network Policies provide pod-level isolation. They use podSelectors to select the target Pods and define rules for Ingress (incoming traffic) and Egress (outgoing traffic). Rules can specify communication based on Pods, Namespaces, or IP blocks (`ipBlock`). A Container Network Interface (CNI) plugin that supports NetworkPolicy (e.g., Calico) is required for them to be enforced.

## DNS

CoreDNS is the default DNS server in Kubernetes, responsible for Service Discovery. Pods can discover Services using DNS names like `my-service.my-namespace.svc.cluster.local` (fully qualified), `my-service.my-namespace` (within the same cluster), or `my-service` (within the same namespace). Each Pod gets its own DNS configuration, inheriting from the cluster's CoreDNS.

Key facts

Flashcards

What are the four main Service types in Kubernetes?
ClusterIP, NodePort, LoadBalancer, ExternalName.
tap to reveal
Which Kubernetes component implements the Service concept by managing network rules on each node?
kube-proxy.
tap to reveal
What is required for an Ingress resource to function correctly and route external traffic to Services?
An Ingress Controller (e.g., Nginx Ingress Controller).
tap to reveal
How do you restrict network access between pods in Kubernetes?
By creating NetworkPolicy resources.
tap to reveal
What is the fully qualified domain name (FQDN) format for a Service named `my-service` in the `default` namespace?
`my-service.default.svc.cluster.local`.
tap to reveal
What is the default isolation state for pods in Kubernetes regarding network communication?
Pods are non-isolated by default, meaning they can communicate with any other pod.
tap to reveal
Which Service type is used to expose a Service on a static port on each Node's IP address?
NodePort.
tap to reveal
What is the purpose of EndpointSlices?
To provide a more scalable and efficient way to track network endpoints for Services, especially in large clusters.
tap to reveal
Practice questions

Services & Networking: 5 practice questions

Q1. If a Service manifest is applied without specifying `spec.type`, what is the default Service type that Kubernetes will create?
  • A.  ClusterIP
  • B.  LoadBalancer
  • C.  NodePort
  • D.  ExternalName
Show answer & explanation
✓ Answer: A. ClusterIP
ClusterIP is the default Service type. It exposes the service on an internal IP, making it reachable only from within the cluster.
Q2. You have applied a NetworkPolicy that selects a group of pods using a podSelector. The policy contains only an `ingress` rule. What happens to egress traffic originating from these pods?
  • A.  Egress traffic is only allowed to other pods selected by the policy.
  • B.  Egress traffic is unaffected until an `egress` rule is defined.
  • C.  All egress traffic is denied by default.
  • D.  All egress traffic is allowed by default.
Show answer & explanation
✓ Answer: C. All egress traffic is denied by default.
Once a pod is selected by any NetworkPolicy, it becomes isolated. If an egress section is not defined, all outbound traffic is denied.
Q3. Which kube-proxy mode is generally considered the most performant for clusters with a very large number of Services, as it uses in-kernel hash tables for routing?
  • A.  iptables
  • B.  ipvs
  • C.  kernelspace
  • D.  userspace
Show answer & explanation
✓ Answer: B. ipvs
The IPVS (IP Virtual Server) mode leverages the Linux kernel's Layer 4 load balancing, which is more efficient and scalable than using iptables rules.
Q4. An administrator creates an Ingress resource, but external traffic is not being routed to the specified Service. What essential cluster component is most likely missing or misconfigured?
  • A.  An Egress Gateway
  • B.  A CNI Plugin
  • C.  A default StorageClass
  • D.  An Ingress Controller
Show answer & explanation
✓ Answer: D. An Ingress Controller
An Ingress resource is only a set of rules. An Ingress Controller (like NGINX or Traefik) is the actual component that reads and implements these rules.
Q5. By default, what is the valid port range that can be used when creating a Service of type NodePort?
  • A.  Any port above 1024
  • B.  30000-32767
  • C.  8000-12000
  • D.  1-1024
Show answer & explanation
✓ Answer: B. 30000-32767
The default port range for NodePort services is 30000-32767. This range is configurable on the kube-api-server via a command-line flag.
Test yourself
See the Certified Kubernetes Administrator (CKA) page

More Certified Kubernetes Administrator (CKA) topics