Accessing Kubernetes service on port 80
If you don't use any cloudproviders, you can just set externalIPs
option in service and make this IP up on node, and kube-proxy will route traffic from this IP to your pod for you.
{ "kind": "Service", "apiVersion": "v1", "metadata": { "name": "my-service" }, "spec": { "selector": { "app": "MyApp" }, "ports": [ { "name": "http", "protocol": "TCP", "port": 80, "targetPort": 9376 } ], "externalIPs" : [ "80.11.12.10" ] }}
https://kubernetes.io/docs/concepts/services-networking/service/#external-ips
If you want to use cloud provider's LB, assuming your app expose on port 8080 and you want to publicly expose it on port 80, here is how the configuration should look:
apiVersion: v1kind: Servicemetadata: name: flask_app labels: run: flask_app namespace: defaultspec: type: LoadBalancer ports: - port: 80 targetPort: 8080 protocol: TCP name: http selector: run: flask_app---apiVersion: extensions/v1beta1kind: Deploymentmetadata: name: flask_app namespace: defaultspec: replicas: 1 strategy: rollingUpdate: maxSurge: 1 maxUnavailable: 0 type: RollingUpdate template: metadata: labels: run: flask_app spec: restartPolicy: Always terminationGracePeriodSeconds: 60 containers: - name: flask_app image: repo/flask_app:latest ports: - containerPort: 8080 imagePullPolicy: Always
Another option is to use a Ingress Controller, for example Nginx.
https://kubernetes.io/docs/concepts/services-networking/ingress/