Step 1: Create the Pod and Service
To begin, create a Pod named check-ip
in the default
namespace and expose it via a ClusterIP Service:
1 2 3 4 5 |
kubectl run check-ip --image=httpd:2.4.41-alpine --restart=Never kubectl expose pod check-ip --name=check-ip-service --port=80 |
Step 2: Retrieve the IP of the Service
Retrieve the ClusterIP of the check-ip-service
to check its initial configuration:
1 2 3 4 |
kubectl get svc check-ip-service |
Step 3: Change the Service CIDR
To change the Service CIDR for the cluster, follow these steps:
SSH into the control plane node:
1 2 3 4 |
ssh cluster2-controlplane1 |
Edit the kube-apiserver
manifest to update the --service-cluster-ip-range
parameter:
1 2 3 4 |
vim /etc/kubernetes/manifests/kube-apiserver.yaml |
Change the line to:
1 2 3 4 |
--service-cluster-ip-range=11.96.0.0/12 |
Save the file and wait for the kube-apiserver
to restart.
Similarly, update the kube-controller-manager
manifest:
1 2 3 4 |
vim /etc/kubernetes/manifests/kube-controller-manager.yaml |
Change the line to:
1 2 3 4 |
--service-cluster-ip-range=11.96.0.0/12 |
Save the file and wait for the kube-controller-manager
to restart.
Step 4: Verify the Change
Create a second Service pointing to the same Pod:
1 2 3 4 |
kubectl expose pod check-ip --name=check-ip-service2 --port=80 |
Verify the IP address of both services:
1 2 3 4 |
kubectl get svc check-ip-service check-ip-service2 |
Expected Results
Service 1 (check-ip-service
) should retain its original IP.
Service 2 (check-ip-service2
) should have an IP from the new CIDR range (11.96.0.0/12
).
Conclusion
This process demonstrates how to change the Service CIDR in a Kubernetes cluster and verify the changes by creating new services to see the updated IP ranges.