在Kubernetes上安装nginx-ingress以在localhost上运行MacO - Docker for Mac(Edge)

时间:2018-01-18 12:08:31

标签: kubernetes kubernetes-helm

更新

我让NodePort工作:kubectl get services

NAME                                       TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)                      AGE
kubernetes                                 ClusterIP   10.96.0.1       <none>        443/TCP                      7d
my-release-nginx-ingress-controller        NodePort    10.105.64.135   <none>        80:32706/TCP,443:32253/TCP   10m
my-release-nginx-ingress-default-backend   ClusterIP   10.98.230.24    <none>        80/TCP                       10m

我可以移植吗?

在Docker for Mac上使用Helm安装Ingress(带Kubernetes的Edge)

https://github.com/kubernetes/charts/tree/master/stable/nginx-ingress

这是否可以在localhost上运行 - 如果是,如何访问服务?

步骤:

  1. helm install stable/nginx-ingress
  2. 输出:

    NAME:   washing-jackal
    LAST DEPLOYED: Thu Jan 18 12:57:40 2018
    NAMESPACE: default
    STATUS: DEPLOYED
    
    RESOURCES:
    ==> v1/ConfigMap
    NAME                                     DATA  AGE
    washing-jackal-nginx-ingress-controller  1     1s
    
    ==> v1/Service
    NAME                                          TYPE          CLUSTER-IP     EXTERNAL-IP  PORT(S)                     AGE
    washing-jackal-nginx-ingress-controller       LoadBalancer  10.105.122.1   <pending>    80:31494/TCP,443:32136/TCP  1s
    washing-jackal-nginx-ingress-default-backend  ClusterIP     10.103.189.14  <none>       80/TCP                      1s
    
    ==> v1beta1/Deployment
    NAME                                          DESIRED  CURRENT  UP-TO-DATE  AVAILABLE  AGE
    washing-jackal-nginx-ingress-controller       1        1        1           0          0s
    washing-jackal-nginx-ingress-default-backend  1        1        1           0          0s
    
    ==> v1/Pod(related)
    NAME                                                           READY  STATUS             RESTARTS  AGE
    washing-jackal-nginx-ingress-controller-5b4d86c948-xxlrt       0/1    ContainerCreating  0         0s
    washing-jackal-nginx-ingress-default-backend-57947f94c6-h4sz6  0/1    ContainerCreating  0         0s
    
    
    NOTES:
    The nginx-ingress controller has been installed.
    It may take a few minutes for the LoadBalancer IP to be available.
    You can watch the status by running 'kubectl --namespace default get services -o wide -w washing-jackal-nginx-ingress-controller'
    
    An example Ingress that makes use of the controller:
    
      apiVersion: extensions/v1beta1
      kind: Ingress
      metadata:
        annotations:
          kubernetes.io/ingress.class: nginx
        name: example
        namespace: foo
      spec:
        rules:
          - host: www.example.com
            http:
              paths:
                - backend:
                    serviceName: exampleService
                    servicePort: 80
                  path: /
        # This section is only required if TLS is to be enabled for the Ingress
        tls:
            - hosts:
                - www.example.com
              secretName: example-tls
    
    If TLS is enabled for the Ingress, a Secret containing the certificate and key must also be provided:
    
      apiVersion: v1
      kind: Secret
      metadata:
        name: example-tls
        namespace: foo
      data:
        tls.crt: <base64 encoded cert>
        tls.key: <base64 encoded key>
      type: kubernetes.io/tls
    

2 个答案:

答案 0 :(得分:5)

据我发布的输出结果可知,一切都应该在你当地的kubernetes集群中顺利运行。

但是,您可以使用LoadBalancer Service公开您的入口控制器,您可以从发布的输出的以下部分中看出:

==> v1/Service
NAME                                          TYPE          CLUSTER-IP     EXTERNAL-IP  PORT(S)                     AGE
washing-jackal-nginx-ingress-controller       LoadBalancer  10.105.122.1   <pending>    80:31494/TCP,443:32136/TCP  1s 

LoadBalancer类型的服务需要来自底层基础架构的支持,并且无法在您的本地环境中运行。

但是,LoadBalancer服务也是NodePort服务。实际上,您可以在上面的输出片段中看到您的入口控制器正在侦听以下端口:

80:31494/TCP,443:32136/TCP

这意味着您应该能够通过节点的IP地址上的端口31494和32136访问入口控制器。

您可以让入口控制器侦听更多标准端口,例如80和443,但您可能必须手动编辑由掌舵图创建的资源才能执行此操作。

答案 1 :(得分:0)

要查看应用正在运行,您需要转到localhost:端口,以便在使用minikube时查看您的服务。如果您在网络中的其他计算机上,请使用您的计算机名称而不是localhost。如果您正在使用VM,请在浏览器中使用节点的VM IP而不是localhost。