0

我一直在用 Helm 图表玩 DevSpace,并可能从 Skaffold 和 Kubernetes 清单迁移到它。我似乎无法让入口控制器为本地开发工作:返回404 Not Found. 我可以通过端口转发访问它,但是,在localhost:3000.

就像我一直做的那样,我首先安装了ingress-nginx控制器docker-desktop

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.0.0/deploy/static/provider/cloud/deploy.yaml

然后在我的devspace.yaml我有以下内容:

version: v1beta10

images:
  client:
    image: app/client
    dockerfile: client/Dockerfile
    context: client/

deployments:
- name: client
  helm:
    componentChart: true
    values:
      containers:
      - image: app/client
      service:
        ports:
          - port: 3000
      ingress:
        name: ingress
        rules: 
        - host: localhost
          path: /
          pathType: Prefix
          servicePort: 3000
          serviceName: client
dev:
  ports:
  - name: client
    imageSelector: app/client
    forward:
    - port: 3000
      remotePort: 3000
  sync:
  - name: client
    imageSelector: app/client
    localSubPath: ./client
    excludePaths: 
    - .git/
    - node_modules/

Dockerfile两种配置都是一样的。

FROM node:14-alpine
WORKDIR /app
COPY ./package.json ./
ENV CI=true
RUN npm install
COPY . .
EXPOSE 3000
CMD ["npm", "start"]

此外,我注意到当我添加相应的服务(例如/api/admin等)时ingress.rules,它会为每个服务创建一个入口,而不是为整个应用程序创建一个入口。

作为参考,这是我曾经做过的事情skaffold并表现出来:

# ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: "nginx"
  name: ingress-dev
spec:
  rules:
    - host: localhost
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: client-cluster-ip-service-dev
                port:
                  number: 3000
# client.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: client-deployment-dev
spec:
  replicas: 1
  revisionHistoryLimit: 5
  selector:
    matchLabels:
      component: client
      environment: development
  template:
    metadata:
      labels:
        component: client
        environment: development
    spec:
      containers:
        - name: client
          image: client
          ports:
            - containerPort: 3000
---
apiVersion: v1
kind: Service
metadata:
  name: client-cluster-ip-service-dev
spec:
  type: ClusterIP
  selector:
    component: client
    environment: development
  ports:
    - port: 3000
      targetPort: 3000
# skaffold.yaml
apiVersion: skaffold/v2beta1
kind: Config
build:
  artifacts:
  - image: client
    context: client
    sync:
      manual:
      - src: 'src/**/*.js'
        dest: .
      - src: 'src/**/*.jsx'
        dest: .
      - src: 'package.json'
        dest: .
      - src: 'public/**/*.html'
        dest: .
      - src: 'src/assets/sass/**/*.scss'
        dest: .
      - src: 'src/build/**/*.js'
        dest: .
    docker:
      dockerfile: Dockerfile.dev
  local:
    push: false
deploy:
  kubectl:
    manifests:
      - k8s/ingress.yaml 
      - k8s/client.yaml

我更喜欢ingress在开发过程中使用控制器而不是端口转发。这样我就可以转到localhost/, localhost/admin,localhost/api等。在此之前我遇到了严重的错误,没有使用端口转发,而是使用入口控制器,所以我不相信它。

任何建议:

  1. 让入口工作以便它到达服务?
  2. 设置devspace.yaml它以便为每个服务创建一个入口而不是一个入口?

devspace render:_

---
# Source: component-chart/templates/service.yaml
apiVersion: v1
kind: Service
metadata:
  name: "client"
  labels:
    "app.kubernetes.io/name": "client"
    "app.kubernetes.io/managed-by": "Helm"
  annotations:
    "helm.sh/chart": "component-chart-0.8.2"
spec:
  externalIPs:
  ports:
    - name: "port-0"
      port: 3000
      targetPort: 3000
      protocol: "TCP"
  selector:
    "app.kubernetes.io/name": "devspace-app"
    "app.kubernetes.io/component": "client"
  type: "ClusterIP"
---
# Source: component-chart/templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: "client"
  labels:
    "app.kubernetes.io/name": "devspace-app"
    "app.kubernetes.io/component": "client"
    "app.kubernetes.io/managed-by": "Helm"
  annotations:
    "helm.sh/chart": "component-chart-0.8.2"
spec:
  replicas: 1
  strategy:
    type: Recreate
  selector:
    matchLabels:
      "app.kubernetes.io/name": "devspace-app"
      "app.kubernetes.io/component": "client"
      "app.kubernetes.io/managed-by": "Helm"
  template:
    metadata:
      labels:
        "app.kubernetes.io/name": "devspace-app"
        "app.kubernetes.io/component": "client"
        "app.kubernetes.io/managed-by": "Helm"
      annotations:
        "helm.sh/chart": "component-chart-0.8.2"
    spec:
      imagePullSecrets:
      nodeSelector:
        null
      nodeName:
        null
      affinity:
        null
      tolerations:
        null
      dnsConfig:
        null
      hostAliases:
        null
      overhead:
        null
      readinessGates:
        null
      securityContext:
        null
      topologySpreadConstraints:
        null
      terminationGracePeriodSeconds: 5
      ephemeralContainers:
        null
      containers:
        - image: "croner-app/client:AtrvTRR"
          name: "container-0"
          command:
          args:
          env:
            null
          envFrom:
            null
          securityContext:
            null
          lifecycle:
            null
          livenessProbe:
            null
          readinessProbe:
            null
          startupProbe:
            null
          volumeDevices:
            null
          volumeMounts:
      initContainers:
      volumes:
  volumeClaimTemplates:
---
# Source: component-chart/templates/ingress.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: "ingress"
  labels:
    "app.kubernetes.io/name": "client"
    "app.kubernetes.io/managed-by": "Helm"
  annotations:
    "helm.sh/chart": "component-chart-0.8.2"
spec:
  rules:
  - host: "localhost"
    http:
      paths:
      - backend:
          serviceName: client
          servicePort: 3000
        path: "/"
        pathType: "Prefix"
---

我能看到的最大区别是我以前使用的是 isapiVersion: networking.k8s.io/v1devspace一个 is apiVersion: extensions/v1beta1controller-v1.0.0也许我正在应用的入口控制器不兼容?没有把握...

4

2 回答 2

1

在这种特殊情况下,解决方案是使用ingress-nginx与 DevSpace 使用的版本兼容的旧版本控制器。就我而言,我正在使用devspace v5.16.0-alpha.0并且以下控制器可以使用它:

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v0.49.0/deploy/static/provider/cloud/deploy.yaml

由于此解决方案将随着 和 的较新版本而改变devspace,因此ingress-nginx通常:

  • 确保ingress-nginx控制器版本和devspace版本兼容。
  • 检查devspace render入口配置是如何生成的,以及apiVersion是否与入口控制器版本兼容kubectl apply
于 2021-09-17T15:22:44.760 回答
0

要对此进行调试,您可能需要运行devspace render它来显示 DevSpace 从 Helm 图表生成的普通清单,然后再将它们部署到集群。这样您就可以看到与您的 skaffold 清单相比有什么不同。或者,您可以使用以下命令检查集群内部:

kubectl get service --all -o yaml   # to see all services
kubectl get ingress --all -o yaml   # to see all ingresses

我对问题的实际原因的有根据的猜测是:由于您正在使用componentChart: true,因此不应指定serviceName: client入口。我假设此 serviceName 与组件图表根据 helm 部署的发布名称生成的服务名称不匹配。所以只需serviceName: client从 devspace.yaml 中删除。或者,您可以指定name: client服务以确保它匹配。

有关完整的组件图表规范,请参阅文档:https ://devspace.sh/component-chart/docs/configuration/reference

于 2021-09-16T21:44:53.863 回答