How to organize access to a service in Kubernetes from outside?
sobes.tech AI
Answer from AI
To organize access to a service in Kubernetes from outside, the following methods are usually used:
-
Service of type LoadBalancer — if the cluster runs in the cloud, this type creates an external load balancer with a public IP, through which the service is accessible.
-
NodePort — opens a fixed port on all cluster nodes, through which the service can be accessed from outside using any node's IP and this port.
-
Ingress — an object that manages external access to services, usually via HTTP/HTTPS, with routing, TLS, and other rules. Requires installing an Ingress Controller.
-
External IPs or MetalLB — for bare-metal clusters, MetalLB can be used to assign external IP addresses to services.
Example of creating a LoadBalancer type Service:
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
type: LoadBalancer
selector:
app: my-app
ports:
- protocol: TCP
port: 80
targetPort: 8080
After creating the service, it will receive an external IP, through which it will be accessible from outside.