Kuberentes nginx子域

时间:2017-12-23 12:12:34

标签: kubernetes google-kubernetes-engine

Host2(子域)工作正常,主机1提供错误消息“默认后端 - 404 ”。 web1和web2的dockerfiles都在本地机器上工作,YAML文件几乎完全相同,除了名称变量,nodePort和图像位置等。

任何想法在这里可能出错?

Ingress配置:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress
  annotations:
    kubernetes.io/ingress.global-static-ip-name: test-ip
    kubernetes.io/ingress.class: "nginx"
spec:
  rules:
    - host: host1.com
      http:
        paths:
          - path: /*
            backend:
              serviceName: web1
              servicePort: 80
    - host: sub.host1.com
      http:
        paths:
          - path: /*
            backend:
              serviceName: web2
              servicePort: 80

YAML for web1

apiVersion: v1
kind: Service
metadata:
  name: web1
spec:
  selector:
    app: web1
  type: NodePort
  ports:
    - name: http
      protocol: TCP
      port: 80
      nodePort: 32112
---
apiVersion: apps/v1beta2
kind: Deployment
metadata:
  name: web1-deployment
spec:
  selector:
    matchLabels:
      app: web1
  replicas: 1
    metadata:
      labels:
        app: web1
    spec:
      terminationGracePeriodSeconds: 60
      containers:
        - name: web1
          image: gcr.io/image..
          imagePullPolicy: Always
          ports:
            - containerPort: 80
          # HTTP Health Check
          livenessProbe:
            httpGet:
              path: /
              port: 80
            initialDelaySeconds: 30
            timeoutSeconds: 5

1 个答案:

答案 0 :(得分:0)

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress
  annotations:
    kubernetes.io/ingress.class: "nginx"
spec:
  rules:
    - host: host1.com
      http:
        paths:
          - path: /
            backend:
              serviceName: web1
              servicePort: 80
    - host: sub.host1.com
      http:
       paths:
          - path: /
            backend:
              serviceName: web2
              servicePort: 80

我认为这应该有效。我也使用相同的配置。请更正缩进问题,如果我在yaml中有,请在此处发布