简体   繁体   English

Kuberentes nginx 子域

[英]Kuberentes nginx subdomain

Host2 (subdomain) works perfect, host 1 gives error message ' default backend - 404 '. Host2(子域)工作完美,主机 1 给出错误消息“默认后端 - 404 ”。 Both dockerfiles for web1 and web2 works on local machine and YAML files is almost identical except for name variables, nodePort and image location etc.. web1 和 web2 的 dockerfiles 都在本地机器上工作,除了名称变量、nodePort 和图像位置等之外,YAML 文件几乎相同。

Any ideas what can be wrong here?任何想法这里可能有什么问题?

Ingress config:入口配置:

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用于 web1 的 YAML

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
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

I think this should work.我认为这应该有效。 I am also using same config.我也在使用相同的配置。 Please correct indentation issues if any in the yaml, I posted here请更正 yaml 中的缩进问题,我在此处发布

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM