Google Kubernetes Engine入口TLS不起作用

时间:2018-10-08 20:15:12

标签: kubernetes gitlab google-kubernetes-engine kubernetes-ingress

使用gitlab自动DevOps CI,它已经设置了ingress控制器:

spec:
  rules:
  - host: api.example.com
    http:
      paths:
      - backend:
          serviceName: production-auto-deploy
          servicePort: 5000
        path: /
  tls:
  - hosts:
    - api.example.com
    secretName: production-auto-deploy-tls
status:
  loadBalancer:
    ingress:
    - ip: xxx.xxx.xxx.xxx

http://api.example.com的工作原理很好,但是https://api.example.com首先给我带来证书错误,然后在我添加例外之后,我从Google Kubernetes Engine获得了404

为什么未正确配置TLS证书?

为什么不将主机定向到服务?

负载均衡器

apiVersion: v1
kind: Service
spec:
  clusterIP: xxx.xxx.xxx.xxx
  externalTrafficPolicy: Cluster
  ports:
  - name: http
    nodePort: 30408
    port: 80
    protocol: TCP
    targetPort: http
  - name: https
    nodePort: 31101
    port: 443
    protocol: TCP
    targetPort: https
  selector:
    app: nginx-ingress
    component: controller
release: ingress

sessionAffinity:无   类型:LoadBalancer 状态:   loadBalancer:     入口:     -ip:xxx.xxx.xxx.xxx

入口

apiVersion: v1
kind: Service
spec:
  clusterIP: xxx.xxx.xxx.xxx
  ports:
  - name: http
    port: 80
    protocol: TCP
    targetPort: http
  selector:
    app: nginx-ingress
    component: default-backend
    release: ingress
  sessionAffinity: None
  type: ClusterIP

status:
  loadBalancer: {}

1 个答案:

答案 0 :(得分:1)

好的,最后我明白了你的所作所为。 您创建了NGINX服务,该服务将平衡您的服务(例如Ingress)。 我不明白带有CLUSTER_IP的NGINX服务如何向世界开放并用作入口。

但是这里有计划将GKE服务暴露给WORLD。 1)使用clusterIp配置的服务,它将在k8s集群内部监听 2)配置入口规则。 3)如果要在GKE上使用可选的入口控制器,请安装控制器。 这是在GCLB上如何工作的示例。(对于GCLB,服务必须在NodePort上公开,这是错误的设计)

服务 apiVersion: v1 kind: Service labels: app: service-nm name: service-name namespace: your-nm spec: externalTrafficPolicy: Cluster ports: - nodePort: 30200 port: 80 protocol: TCP targetPort: 3001 selector: app: operator sessionAffinity: None type: NodePort 出口 apiVersion: extensions/v1beta1 kind: Ingress metadata: annotations: kubernetes.io/ingress.allow-http: false ingress.gcp.kubernetes.io/pre-shared-cert: np-ssl-certificate spec: rules: - host: your domain-name http: paths: - backend: serviceName: your-sn servicePort: 80 - host: your-domain-name 有关更多详细信息,如何在GKE上安装Nginx https://cloud.google.com/community/tutorials/nginx-ingress-gke