GKE进入具有2个裸露端口的同一容器上的服务

时间:2020-03-01 19:34:39

标签: google-cloud-platform google-kubernetes-engine kubernetes-ingress

我有一个GKE群集,一个静态ip和一个容器/容器,该容器/容器公开2个端口:8081(UI https)和8082(WSS https)。我必须连接到同一IP上的“ UI Https”和“ WSS Https”。 “ WSS Https”服务没有没有运行状况检查终结点。

我需要使用Isito,Consul,Nginx入口或某些服务网格来允许这些IP连接到具有不同端口的同一IP吗?

这有可能吗? enter image description here

我尝试过的事情:

  1. 具有2个独立入口服务的GCP全局磅。第二项服务的Yaml永远无法正常工作,但我可以通过UI添加另一项支持的服务。入口始终恢复为“ WSS Https”服务的默认运行状况检查,并且始终不正常。
  2. 通过静态IP将服务类型从NodePort更改为LoadBalancer。这将不允许我更改准备情况检查并始终还原。
  3. 具有1个入口和2个后端的GCP GLIB给了我与上面相同的运行状况检查失败
  4. TCP代理-不允许我设置相同的实例组。

下面是我的入口,服务和部署。

入口

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: app-ingress
  namespace: myappnamespace
  annotations:
    kubernetes.io/ingress.global-static-ip-name: global-static-ip-name
  labels:
    app: appname
spec:
  backend:
    serviceName: ui-service
    servicePort: 8081
  tls:
  - hosts:
    - my-host-name.com
    secretName: my-secret
  rules:
  - host: my-host-name.com
    http:
      paths:
        - backend:
            serviceName: ui-service
            servicePort: 8081
  - host: my-host-name.com
    http:
      paths:
        - backend:
            serviceName: app-service
            servicePort: 8082

服务

---
apiVersion: v1
kind: Service
metadata:
  labels:
    name: ui-service
  name: ui-service
  namespace: myappnamespace
  annotations:
    cloud.google.com/app-protocols: '{"ui-https":"HTTPS"}'
    beta.cloud.google.com/backend-config: '{"ports":{"8081":"cloud-armor"}}'
spec:
  selector:
      app: appname
  ports:
  - name: ui-https
    port: 8081
    targetPort: "ui"
    protocol: "TCP"
  selector:
    name: appname
  type: NodePort
---
apiVersion: v1
kind: Service
metadata:
  labels:
    name: app-service
  name: app-service
  namespace: myappnamespace
  annotations:
    cloud.google.com/app-protocols: '{"serviceport-https":"HTTPS"}'
    beta.cloud.google.com/backend-config: '{"ports":{"8082":"cloud-armor"}}'
spec:
  selector:
      app: appname
  ports:
  - name: serviceport-https
    port: 8082
    targetPort: "service-port"
    protocol: "TCP"
  selector:
    name: appname
  type: NodePort
---

部署

apiVersion: apps/v1
kind: Deployment
metadata:
    name: appname
    namespace: myappnamespace
    labels:
        name: appname
spec:
    replicas:1
    selector:
        matchLabels:
            name: appname
    strategy:
        type: Recreate
    template:
        metadata:
            name: appname
            namespace: appnamespace
            labels:
                name: appname
        spec:
            restartPolicy: Always
            serviceAccountName: myserviceaccount
            containers:
            - name: my-container
              image: image
              ports:
              - name: service-port
                containerPort: 8082
              - name: ui
                containerPort: 8081
              readinessProbe:
              failureThreshold: 3
              httpGet:
               path: /api/health
                 port: 8081
                 scheme: HTTPS
        livenessProbe:
          exec:
            command:
              - cat
              - /version.txt
        [......]

1 个答案:

答案 0 :(得分:1)

通过入口公开的服务必须响应来自负载均衡器的health checks

GKE Ingress创建的外部HTTP(S)负载均衡器仅支持https流量的端口443。

在这种情况下,您可能想要:

  1. 使用两个单独的Ingress资源为同一IP地址和端口上的两个不同主机名路由流量:

    • ui-https.my-host-name.com

    • wss-https.my-host-name.com

  2. 选择使用AmbassadorIstio Virtual Service

  3. 尝试Multi-Port Services

请让我知道是否有帮助。