How to Set Up External Access for My Kubernetes Cluster?

0
17
Asked By CuriousCoder47 On

Hey folks! I'm trying to configure external access for my application running in a Kubernetes cluster. I have a container with an ingress that listens on port 8080, and I've noticed the ingress details in k9s showing 172 addresses. My goal is to set up a load balancer to enable outside access, but I'm having some trouble making it work based on my current configuration.

Here's what I have:

### Ingress Configuration:
```yaml
ingresses:
my-app:
enabled: true
className: "traefik"
customAnnotations: {}
hosts:
- host: "myapp.apps.caspersbox.com"
paths:
- path: /actuator/health
serviceName: "my-app"
servicePort: 8081
type: "Prefix"
- path: /
serviceName: "my-app"
servicePort: 8080
type: "Prefix"
```

### Load Balancer Service:
```yaml
apiVersion: v1
kind: Service
metadata:
name: lb-service
spec:
selector:
app: myapp
type: LoadBalancer
ports:
- name: http-ui
protocol: TCP
port: 443
targetPort: 8080
```

I set up MetalLB with the following configurations:
```yaml
apiVersion: metallb.io/v1beta1
kind: IPAddressPool
metadata:
name: default-pool
namespace: my-ns
spec:
addresses:
- 192.168.10.25-192.168.10.29

---
apiVersion: metallb.io/v1beta1
kind: L2Advertisement
metadata:
name: default-advertisement
namespace: myns
spec:
ipAddressPools:
- default-pool
```

Now, I have an IP assigned, but I'm seeing a port mapping issue where the port is 443 externally, but it shows port 32470 when I check in k9s. I'm not sure where I went wrong, and I'm looking for either a usable IP address on my network or for the service to be accessible via the host IP. Any suggestions?

1 Answer

Answered By KubeGuru89 On

It seems like you're trying to use both an Ingress and a LoadBalancer at the same time, which can be a bit tricky. First, make sure you’re correctly using the Ingress to point to your services. Run `kubectl -A get ingress` to see if the `ADDRESS` column has a value. If you see a LoadBalancer IP there, your Ingress is working fine.

If it’s not showing an IP, you need to ensure your service is set up correctly. You can’t change the service type after creation, so you might need to delete and recreate it with the right type or simply switch it to the service that matches what your Ingress points to, adjusting the ports as needed.

If you’re okay without the Ingress, just check the `get svc -A` output to see if the `EXTERNAL-IP` is populated. That’ll help you determine if the LoadBalancer is set up correctly.

TechSavvySam -

So just to clarify, are you saying I can disable the Ingress and have the LoadBalancer route directly to the container's port? Also, I turned off the Ingress and updated the LoadBalancer service, but it seems to be ignoring my targetPort settings.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.