1

我在 Kubernetes 上为 Traefik 设置了以下 Ingress 和部署。我在实际域名上不断收到错误的网关错误。

出于某种原因,服务无法正常工作,或者我的连接有误,或者选择器有问题等。

apiVersion: v1
kind: Service
metadata:
  name: web
  labels:
    app: wordpress
spec:
  selector:
    k8s-app: traefik-ingress-lb
  ports:
    - name: http
      port: 80
      targetPort: 80
      protocol: TCP
  selector:
    app: wordpress

---

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: web-ingress
  annotations:
    kubernetes.io/ingress.class: traefik
    # traefik.ingress.kubernetes.io/frontend-entry-points: http,https
spec:
  rules:
  - host: test.example.services
    http:
      paths:
      - path: /
        backend:
          serviceName: web
          servicePort: http




---
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
  name: wordpress
  labels:
    app: wordpress
spec:
  selector:
    matchLabels:
      app: wordpress
      tier: frontend
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: wordpress
        tier: frontend
    spec:
      containers:
      - image: wordpress:4.8-apache
        name: wordpress
        env:
        - name: WORDPRESS_DB_HOST
          value: wordpress-mysql
        - name: WORDPRESS_DB_PASSWORD
          valueFrom:
            secretKeyRef:
              name: mysql-pass
              key: password
        ports:
        - containerPort: 80
          name: wordpress
        volumeMounts:
        - name: wordpress-persistent-storage
          mountPath: /var/www/html
      volumes:
      - name: wordpress-persistent-storage
        persistentVolumeClaim:
          claimName: wp-pv-claim

我的代码如下,所以如果有任何更正,请提供建议。

4

1 回答 1

0

有几件事情需要考虑:

  1. 我看到你namsespace:在你的metadata:. 检查是否是这种情况。

  2. 尝试创建两个服务。一个用于wordpress和一个用于 treafik-ingress-lb。

  3. 之后可能使用了太多空格ports:。尝试这样的事情:

      ports:
      - name: http
        port: 80
        targetPort: 80
        protocol: TCP
  1. 检查您的标签是否配置正确。如果您需要有关它们的更多详细信息,请尝试此文档

请让我知道这是否有帮助。

于 2019-08-14T08:16:25.693 回答