I have a service object of type LoadBalancer
:
NAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
default user-api LoadBalancer 10.106.120.69 <pending> 9411:31622/TCP,3000:31878/TCP,4000:30202/TCP,3001:31656/TCP,4001:31455/TCP 96m
I can reach to the service internally with 3000 port via internal_ip:31878
.
Supposing I have a public_ip and ingress, how should I correctly configure it to let the internal service to reach to the internet?
NAME HOSTS ADDRESS PORTS AGE
app-ingress user-api.my-domain.com 80 95m
again, I'm guessing that this was a cluster setup by kubeadm
because of your other questions and again the solution is to install an external load-balancer plugin such as metalLB. After that your loadbalancers will get IPs assigned automatically and all ports of your services/ingress will be open on this IP and will lead to your pods.
Installing metalLB is very easy:
kubectl apply -f https://raw.githubusercontent.com/google/metallb/v0.8.3/manifests/metallb.yaml
create and apply config of IP pools to be used for your load-balancers similarly to this one:
apiVersion: v1
kind: ConfigMap
metadata:
namespace: metallb-system
name: config
data:
config: |
address-pools:
- name: default
protocol: layer2
addresses:
- 92.18.1.200-92.18.1.250
If you have a service object of type LoadBalancer
, you should already be able to reach to the service from the Internet. If you have a Load Balancer that is attached to an Ingress Controller, you should change the type of your service object (to something like ClusterIP
) and register the service in the Ingress Controller manifest. Example is:
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: test-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- http:
paths:
- path: /<context-path>
backend:
serviceName: <service-name>
servicePort: <service-port>