It is possible to use Kubernetes NodePort to act as external service.
NodePorts will expose a port on each of your hosts that you can use to reach your service.
The downside of this approach is dealing with port-management.
Applications can no assume same things like HTTPS is port 443, or that MySQL runs on port 3306.
Instead, it may live on port 32042 in PROD, and 32012 in DEV.
Consider using NodePort that way
is a gaping hole in cluster security, moreover NodePort cannot expose standard low-numbered
ports like 80 and 443.
apiVersion: v1
kind: Service
metadata:
name: my-nodeport-service
spec:
selector:
app: my-app
type: NodePort
ports:
- name: http
port: 80
targetPort: 80
nodePort: 30036
protocol: TCP
With ingress, you can run a software load balancer such as nginx, expose it as port 80/443 on
all your hosts and then control routing any HTTP traffic to Kuberbetes services.
This works best for layer 7 traffic like HTTP/HTTPS.
You may try Ingress resources and Ingress controller and an external load balancer
or public IP to enable path-based routing of external requests to internal Services.
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: my-ingress
spec:
backend:
serviceName: other
servicePort: 8080
rules:
- host: foo.mydomain.com
http:
paths:
- backend:
serviceName: foo
servicePort: 8080
- host: mydomain.com
http:
paths:
- path: /bar/*
backend:
serviceName: bar
servicePort: 8080
Inspirated by
think-nodeport-kubernetes and cloud kubernetes nodeport vs ingress article.