Skip to content

Commit

Permalink
Update 2023-08-11-kubernetes-change-service-type.md
Browse files Browse the repository at this point in the history
  • Loading branch information
andregri authored Aug 11, 2023
1 parent 6d6586a commit 8f3a7db
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions _posts/2023-08-11-kubernetes-change-service-type.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---
layout: single
title: Change Kubernetes service type LoadBalancer or NodePort
title: Change Kubernetes service type from LoadBalancer to NodePort and viceversa
toc: true
tags: kubernetes operator go
tags: kubernetes
---

Changing the Service type from NodePort to LoadBalancer and viceversa is useful depending on the cluster you are working on. If you are doing experiments in a local development cluster, like Kind, you don't have a real load balancer in front of your cluster and you need to expose your services externally using a NodePort service. On contrary, if you are working on a kubernetes cluster with a proper load balancer, you can expose your services through a LoadBalancer service type that uses the load balancer domain name and port.

# Convert to a LoadBalancer service
## Convert to a LoadBalancer service

It is very likely to have a load balancer in front of your kubernetes services when you are working in a production cluster or on a kubernetes cluster hosted by a cloud provider. The load balancer is useful to expose your services using a single domain name, the load balancer domain name.

Expand All @@ -17,7 +17,7 @@ The command to convert a service type to a LoadBalancer service type is:
kubectl patch svc <service-name> -n <namespace> -p '{"spec": {"type": "LoadBalancer"}}'
```

# Convert to a NodePort service
## Convert to a NodePort service

If you are working on a development kubernetes cluster you probably don't have a load balancer to forward the incoming requests to the services. To connect to your services you have to expose them using a Node Port service type that open the same port on each node of the cluster. So to connect to the service in a multi-node cluster, you type the name of a node and the exposed port. Compared to a load balancer, you should know the node names before connecting to the service.

Expand All @@ -27,7 +27,7 @@ The command to convert a service type to a NodePort service type is:
kubectl patch svc <service-name> -n <namespace> -p '{"spec": {"type": "NodePort"}}'
```

# kubectl port-forward to expose a service locally
## kubectl port-forward to expose a service locally

kubectl tool contains the port-forward command to expose a service locally on the port we choose. It means you can connect to the service using `localhost:port`.

Expand All @@ -49,7 +49,7 @@ The [Argo CD Getting Started guide](https://argo-cd.readthedocs.io/en/stable/get

I personally used the combination of a NodePort service and kubectl port-forward command when working with Istio Gateways. Istio creates a LoadbBalancer service when you create a Gateway. Since I was working in a Kind cluster, I first changed the service type and then I exposed it locally.

# Conclusion
## Conclusion

Depending if you a have load balancer or not, you may need to change service type to connect to them.

Expand Down

0 comments on commit 8f3a7db

Please sign in to comment.