I have a k8s service of type clusterIP.. i need to change the below configuration via CLI
Is there a way to do it..?
The LoadBalancer type is an extension of the NodePort type. So a Service of type LoadBalancer has a cluster IP address and one or more nodePort values.
This kind of algorithm works by monitoring changes in response latency as the load adjusts based on server capacity. The Kubernetes load balancer sends connections to the first server in the pool until it is at capacity, and then sends new connections to the next available server.
You can't remove the existing port, but you can add the HTTPs port and also change the type using kubectl patch
Example:
kubectl patch svc <my_service> -p '{"spec": {"ports": [{"port": 443,"targetPort": 443,"name": "https"},{"port": 80,"targetPort": 80,"name": "http"}],"type": "LoadBalancer"}}'
If you don't want to create JSON on the command line, create a yaml file like so:
ports:
- port: 443
targetPort: 443
name: "https"
- port: 80
targetPort: 80
name: "http"
type: LoadBalancer
And then do:
kubectl patch svc <my_service> --patch "$(cat patch.yaml)"
kubectl edit svc <service_name> -n <namespace>
i - to edit the service
ESC, :wq - update your service
Use kubectl patch svc <service_name> -p '{"spec": ....}'
if you don't want the prompt.
The original solution does not works on powershell. Here is the following we need to do in order to make it work.
kubectl patch
Powershell:
kubectl patch svc <my_service> -p '{\"spec\": {\"ports\": [{\"port\": 443,\"targetPort\": 443,\"name\": \"https\"},{\"port\": 80,\"targetPort\": 80,\"name\": \"http\"}],\"type\": \"LoadBalancer\"}}'
.
Notice the \ for powershell use case.
Bash:
kubectl patch svc <my_service> -p '{"spec": {"ports": [{"port": 443,"targetPort": 443,"name": "https"},{"port": 80,"targetPort": 80,"name": "http"}],"type": "LoadBalancer"}}'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With