Configure Kubernetes nginx for an external access

允我心安 提交于 2020-01-06 11:48:31

问题


I'm still new to Kubernetes and Lagom.

I need to invoke my Lagom microservice from an external server. To do that, I think that I need to expose my nginx-ingress for an external access, but I don't know how. Should I configure an "externalIPs"?

{
  "apiVersion": "v1",
  "kind": "Service",
  "metadata": {
    "name": "nginx-ingress"
  },
  "spec": {
    "type": "LoadBalancer",
    "ports": [
      {
        "port": 80,
        "name": "http",
        "targetPort": 8080
      },
      {
        "port": 443,
        "name": "https"
      }
    ],
    "externalIPs": [
      "192.168.1.120"
    ],
    "selector": {
      "k8s-app": "nginx-ingress-lb"
    }
  }
}

回答1:


Minikube creates a network for itself and the VM. You need to externally expose your service.

From Op's comment: You get port 30370 for your Service. You need to expose this port.

ssh -i ~/.minikube/machines/minikube/id_rsa docker@$(minikube ip) -L \*:30370:0.0.0.0:30370



回答2:


In Minikube, you would use the kubectl expose command to expose the service for external access per https://kubernetes.io/docs/tutorials/stateless-application/hello-minikube/#create-a-service. Minikube is not used in production.

In production, you have three ways to create the nginx ingress service using kubernetes per https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services---service-types and expose it for external access:

  1. LoadBalancer service type which sets the ExternalIP automatically. This is used when there is an external non-k8s, cloud-provider's load-balancer like CGE, AWS or Azure, and this external load-balancer would provide the ExternalIP for the nginx ingress service.
  2. ExternalIPs per https://kubernetes.io/docs/concepts/services-networking/service/#external-ips.
  3. NodePort. In this approach, the service can be accessed from outside the cluster using NodeIP:NodePort/url/of/the/service.

Along with the nginx ingress controller, you'll need an ingress resource too. Refer https://github.com/nginxinc/kubernetes-ingress/tree/master/examples/complete-example for examples.



来源:https://stackoverflow.com/questions/48691246/configure-kubernetes-nginx-for-an-external-access

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!