Preview Question 2

Verifying kube-proxy Functionality in Kubernetes by Using iptables

In Kubernetes, kube-proxy is responsible for maintaining network rules on nodes, ensuring that communication between services is correctly routed. This post walks through the process of verifying that kube-proxy is functioning correctly on all nodes by using iptables. We’ll create a test Pod and Service, check the iptables rules on all nodes, and then clean up the resources.

Step 1: Create a Test Pod

First, we need to create a Pod named p2-pod with two containers. The first container runs an Nginx server, and the second container runs a BusyBox shell that keeps the Pod alive:

Edit the p2.yaml file to include the BusyBox container:

Apply the configuration to create the Pod:

Step 2: Create a Service

Next, expose the p2-pod using a Service that forwards traffic from port 3000 to port 80 of the Nginx container:

Confirm that the Service and Pod are connected by listing the services and endpoints:

Step 3: Confirm kube-proxy is Running and Using iptables

Now, log into each node and confirm that kube-proxy is running and using iptables. Use the crictl command to inspect the kube-proxy container logs on each node:

Look for the log entry: Using iptables Proxier. Repeat this process for all nodes (e.g., cluster1-node1 and cluster1-node2).

Step 4: Check iptables Rules

To verify that the kube-proxy has correctly configured the iptables rules for the p2-service, check the iptables rules on each node:

Save the iptables rules related to the p2-service into a file:

Step 5: Clean Up

Finally, delete the p2-service and verify that the corresponding iptables rules have been removed from all nodes:

There should be no iptables rules remaining for p2-service.

Conclusion

By following these steps, you can verify that kube-proxy is functioning correctly on all nodes in your Kubernetes cluster. Ensuring that the correct iptables rules are applied is crucial for maintaining proper service communication within the cluster.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *