Bird
Raised Fist0
Kubernetesdevops~10 mins

Container Network Interface (CNI) in Kubernetes - Step-by-Step Execution

Choose your learning style10 modes available
Process Flow - Container Network Interface (CNI)
Pod requests network
↓
Kubelet calls CNI plugin
↓
CNI plugin configures network
↓
Assign IP & setup routes
↓
Pod network ready
↓
Pod communicates over network
Shows how Kubernetes uses CNI plugins to set up networking for pods step-by-step.
Execution Sample
Kubernetes
kubectl apply -f pod.yaml
# Pod starts
# Kubelet calls CNI plugin
# CNI assigns IP
# Pod network ready
This sequence shows how a pod's network is set up using CNI when the pod starts.
Process Table
StepActionComponentResultNotes
1Pod creation requestedUser/Kubernetes APIPod object createdPod spec includes network request
2Kubelet detects pod startKubeletCalls CNI pluginTriggers network setup
3CNI plugin invokedCNI pluginReads config and allocates IPAllocates IP from network pool
4Network interfaces configuredCNI pluginNetwork namespace setupRoutes and interfaces added
5Pod network readyKubeletPod can send/receive packetsPod joins cluster network
6Pod communicatesPodNetwork traffic flowsPod uses assigned IP
7Pod deletedUser/Kubernetes APIKubelet calls CNI DELNetwork resources cleaned up
8CNI cleans networkCNI pluginIP released and interfaces removedPrepares for next pod
9EndSystemPod network lifecycle completeNetwork resources freed
💡 Pod deleted and network cleaned up, ending the network lifecycle
Status Tracker
VariableStartAfter Step 3After Step 4After Step 5Final
Pod IPNone10.244.1.510.244.1.510.244.1.5None
Network InterfacesNoneeth0 createdeth0 configuredeth0 activeRemoved
Routing TableEmptyRoutes addedRoutes activeRoutes activeRoutes removed
Key Moments - 3 Insights
Why does the pod have no IP before the CNI plugin runs?
Before step 3 in the execution_table, the pod network is not set up, so no IP is assigned yet.
What happens if the CNI plugin fails to assign an IP?
The pod network setup fails at step 3, so the pod cannot communicate and will not become ready.
Why is the network cleaned up after pod deletion?
At steps 7 and 8, the CNI plugin removes interfaces and releases IPs to avoid resource leaks for future pods.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what IP is assigned to the pod after step 3?
A10.244.1.5
BNone
C192.168.0.1
D127.0.0.1
💡 Hint
Check the 'Pod IP' variable in variable_tracker after step 3
At which step does the pod network become ready for communication?
AStep 4
BStep 5
CStep 2
DStep 7
💡 Hint
Look for 'Pod network ready' in the execution_table
If the pod is deleted, what happens to the network interfaces?
AThey remain active
BThey are duplicated
CThey are removed
DThey are renamed
💡 Hint
See steps 7 and 8 in execution_table and variable_tracker final state
Concept Snapshot
Container Network Interface (CNI) in Kubernetes:
- Kubelet calls CNI plugin to set up pod network
- CNI plugin assigns IP and configures interfaces
- Pod network ready after setup
- On pod deletion, CNI cleans network resources
- Enables pod communication inside cluster
Full Transcript
Container Network Interface (CNI) is how Kubernetes sets up networking for pods. When a pod starts, the kubelet calls the CNI plugin. The plugin assigns an IP address and configures network interfaces and routes inside the pod's network namespace. Once done, the pod can communicate over the cluster network. When the pod is deleted, the kubelet calls the CNI plugin to clean up network resources like IP addresses and interfaces. This process ensures pods have isolated, functional networking and resources are reused efficiently.

Practice

(1/5)
1. What is the main purpose of the Container Network Interface (CNI) in Kubernetes?
easy
A. To manage storage volumes for containers
B. To provide IP addresses and networking for pods
C. To schedule pods on nodes
D. To monitor container resource usage

Solution

  1. Step 1: Understand CNI role in Kubernetes

    CNI is responsible for setting up networking so pods can communicate.
  2. Step 2: Identify correct function

    Providing IP addresses and network connectivity to pods is the core function of CNI.
  3. Final Answer:

    To provide IP addresses and networking for pods -> Option B
  4. Quick Check:

    CNI = Pod networking [OK]
Hint: CNI is about pod networking, not storage or scheduling [OK]
Common Mistakes:
  • Confusing CNI with storage management
  • Thinking CNI schedules pods
  • Assuming CNI monitors resources
2. Which of the following is a valid CNI configuration file format?
easy
A. XML
B. CSV
C. INI
D. JSON

Solution

  1. Step 1: Recall CNI config formats

    CNI plugins use JSON or YAML files to configure networking.
  2. Step 2: Identify valid format

    JSON is the standard format for CNI configuration files.
  3. Final Answer:

    JSON -> Option D
  4. Quick Check:

    CNI config = JSON [OK]
Hint: CNI configs are JSON or YAML, not XML or INI [OK]
Common Mistakes:
  • Choosing XML as config format
  • Confusing INI or CSV with CNI config
  • Not knowing CNI uses JSON
3. Given this CNI config snippet:
{
  "cniVersion": "0.4.0",
  "name": "mynet",
  "type": "bridge",
  "bridge": "cni0",
  "ipMasq": true,
  "ipam": {
    "type": "host-local",
    "subnet": "10.22.0.0/16"
  }
}

What IP subnet will pods get addresses from?
medium
A. 172.16.0.0/12
B. 192.168.1.0/24
C. 10.22.0.0/16
D. None, IPs are assigned dynamically

Solution

  1. Step 1: Locate subnet in config

    The subnet is specified inside the "ipam" section as "10.22.0.0/16".
  2. Step 2: Understand IP assignment

    Pods will get IPs from the defined subnet range in the config.
  3. Final Answer:

    10.22.0.0/16 -> Option C
  4. Quick Check:

    Subnet in ipam = 10.22.0.0/16 [OK]
Hint: Look inside "ipam" for subnet to find pod IP range [OK]
Common Mistakes:
  • Ignoring the subnet field
  • Choosing default Kubernetes pod subnet
  • Thinking IPs are random without subnet
4. You installed a CNI plugin but pods cannot communicate across nodes. What is a likely cause?
medium
A. CNI config file missing or incorrect
B. Pods have no CPU limits set
C. Kubernetes API server is down
D. Node disk space is full

Solution

  1. Step 1: Analyze pod network failure

    Pods not communicating across nodes usually means network setup is broken.
  2. Step 2: Check CNI config

    If the CNI config file is missing or wrong, networking won't work properly.
  3. Final Answer:

    CNI config file missing or incorrect -> Option A
  4. Quick Check:

    Network issues = CNI config problem [OK]
Hint: Check CNI config file first for network issues [OK]
Common Mistakes:
  • Blaming CPU limits for network problems
  • Assuming API server affects pod networking directly
  • Ignoring CNI config correctness
5. You want to deploy a new CNI plugin that supports network policies and IP address management. Which step is NOT required?
hard
A. Restart the Kubernetes API server
B. Create a CNI configuration file in /etc/cni/net.d/
C. Install the CNI plugin binaries on all nodes
D. Ensure kubelet is configured to use the new CNI

Solution

  1. Step 1: Understand CNI plugin deployment steps

    You must install plugin binaries, add config files, and configure kubelet to use it.
  2. Step 2: Identify unnecessary step

    Restarting the Kubernetes API server is not needed for CNI plugin changes.
  3. Final Answer:

    Restart the Kubernetes API server -> Option A
  4. Quick Check:

    API server restart NOT needed for CNI install [OK]
Hint: API server restart not needed when changing CNI [OK]
Common Mistakes:
  • Thinking API server restart is required
  • Forgetting to install plugin binaries
  • Not placing config in correct directory
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard