我一直在用 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
等。在此之前我遇到了严重的错误,没有使用端口转发,而是使用入口控制器,所以我不相信它。
任何建议:
- 让入口工作以便它到达服务?
- 设置
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/v1
和devspace
一个 is apiVersion: extensions/v1beta1
。controller-v1.0.0
也许我正在应用的入口控制器不兼容?没有把握...