Add External IP to service to access it from outside the cluster

Quote from moshe on 30/12/2021, 7:56 amProblem
User wants to access a kubernetes services outside of the cluster ( for example: Webserver on port 8080 ). there are few options to expose the service
change the service type to LoadBalancer and assign ports running the following command
kubectl -n my-nginx patch svc my-nginx -p ‘{“spec”: {“type”: “LoadBalancer”}}’
or specify Ports
kubectl patch svc <my_service> -p ‘{“spec”: {“ports”: [{“port”: 443,”targetPort”: 443,”name”: “https”},{“port”: 80,”targetPort”: 80,”name”: “http”}],”type”: “LoadBalancer”}}’
if you have deployment
kubectl expose deployment/’deployment-name’ –type=”LoadBalancer”
Change the service type to NodeIP
kubectl patch svc you-svc -p ‘{“spec”: {“type”: “NodePort”}}’
Assign External IP to ClusterIP
kubectl patch svc MYHTTPSERVICE -p '{"spec":{"externalIPs":["192.168.0.194"]}}'
Problem
User wants to access a kubernetes services outside of the cluster ( for example: Webserver on port 8080 ). there are few options to expose the service
change the service type to LoadBalancer and assign ports running the following command
kubectl -n my-nginx patch svc my-nginx -p ‘{“spec”: {“type”: “LoadBalancer”}}’
or specify Ports
kubectl patch svc <my_service> -p ‘{“spec”: {“ports”: [{“port”: 443,”targetPort”: 443,”name”: “https”},{“port”: 80,”targetPort”: 80,”name”: “http”}],”type”: “LoadBalancer”}}’
if you have deployment
kubectl expose deployment/’deployment-name’ –type=”LoadBalancer”
Change the service type to NodeIP
kubectl patch svc you-svc -p ‘{“spec”: {“type”: “NodePort”}}’
Assign External IP to ClusterIP
Uploaded files:kubectl patch svc MYHTTPSERVICE -p '{"spec":{"externalIPs":["192.168.0.194"]}}'