无法在 WSL 2 上访问应用程序 运行 skaffold 和 docker 桌面
Not able access the application running with skaffold and docker desktop on WSL 2
无法访问节点 js 应用程序我 运行 在具有 docker 桌面的 K8s 集群中。下面是对象
Skaffold 配置:
apiVersion: skaffold/v2beta26
kind: Config
deploy:
kubectl:
manifests:
- ./objects/*
build:
local:
push: false
artifacts:
- image: sq/accounts-backend
context: ../accounts-backend
docker:
dockerfile: Dockerfile.dev
sync:
manual:
- src: "**/*.js"
dest: .
- src: "public/**/*.css"
dest: .
部署:
apiVersion: apps/v1
kind: Deployment
metadata:
name: accounts-backend-deployment
spec:
replicas: 2
selector:
matchLabels:
component: accounts-backend
template:
metadata:
labels:
component: accounts-backend
spec:
containers:
- name: accounts-backend
image: sq/accounts-backend
ports:
- containerPort: 5000
env:
集群IP:
apiVersion: v1
kind: Service
metadata:
name: accounts-backend-cluster-ip-service
spec:
type: ClusterIP
selector:
component: accounts-backend
ports:
- port: 5000
targetPort: 5000
入口:
apiVersion: networking.k8s.io/v1
# UPDATE API
kind: Ingress
metadata:
name: ingress-service
annotations:
kubernetes.io/ingress.class: "nginx"
nginx.ingress.kubernetes.io/use-regex: "true"
# ADD ANNOTATION
nginx.ingress.kubernetes.io/rewrite-target: /
# UPDATE ANNOTATION
spec:
rules:
- http:
paths:
- path: /api/?(.*)
# UPDATE PATH
pathType: Prefix
# ADD PATHTYPE
backend:
service:
# UPDATE SERVICE FIELDS
name: accounts-backend-cluster-ip-service
port:
number: 5000
我能够通过执行 skaffold dev
验证 Deployment 已启动并且应用程序 运行。我尝试访问本地主机、127.0.0.1 和 docker 的内部 IP,但无法访问该应用程序。我在浏览器中尝试时连接时间太长,连接被拒绝。
入口的输出描述:
Name: ingress-service
Namespace: default
Address:
Default backend: default-http-backend:80 (<error: endpoints "default-http-backend" not found>)
Rules:
Host Path Backends
---- ---- --------
*
/api/?(.*) accounts-backend-cluster-ip-service:5000 (10.1.0.50:5000,10.1.0.51:5000)
Annotations: kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/rewrite-target: /
nginx.ingress.kubernetes.io/use-regex: true
Events: <none>
默认情况下,skaffold dev
只有port-forwardsuser-definedport-forwards,即explicitly defined in the skaffold.yaml
。例如:
portForward:
- resourceType: deployment
resourceName: accounts-backend-deployment
port: 5000
localPort: 8080
您还可以使用 skaffold dev --port-forward=user,services
port-forward 服务以及任何 user-defined port-forwards.
Skaffold port-forwarding 不包括入口:目前是 cluster-specific。例如,对于 minikube,您需要单独 运行 minikube tunnel
,或者如果使用 nginx-ingress
.
或者 minikube service -n ingress-nginx --url ingress-nginx-controller
无法访问节点 js 应用程序我 运行 在具有 docker 桌面的 K8s 集群中。下面是对象 Skaffold 配置:
apiVersion: skaffold/v2beta26
kind: Config
deploy:
kubectl:
manifests:
- ./objects/*
build:
local:
push: false
artifacts:
- image: sq/accounts-backend
context: ../accounts-backend
docker:
dockerfile: Dockerfile.dev
sync:
manual:
- src: "**/*.js"
dest: .
- src: "public/**/*.css"
dest: .
部署:
apiVersion: apps/v1
kind: Deployment
metadata:
name: accounts-backend-deployment
spec:
replicas: 2
selector:
matchLabels:
component: accounts-backend
template:
metadata:
labels:
component: accounts-backend
spec:
containers:
- name: accounts-backend
image: sq/accounts-backend
ports:
- containerPort: 5000
env:
集群IP:
apiVersion: v1
kind: Service
metadata:
name: accounts-backend-cluster-ip-service
spec:
type: ClusterIP
selector:
component: accounts-backend
ports:
- port: 5000
targetPort: 5000
入口:
apiVersion: networking.k8s.io/v1
# UPDATE API
kind: Ingress
metadata:
name: ingress-service
annotations:
kubernetes.io/ingress.class: "nginx"
nginx.ingress.kubernetes.io/use-regex: "true"
# ADD ANNOTATION
nginx.ingress.kubernetes.io/rewrite-target: /
# UPDATE ANNOTATION
spec:
rules:
- http:
paths:
- path: /api/?(.*)
# UPDATE PATH
pathType: Prefix
# ADD PATHTYPE
backend:
service:
# UPDATE SERVICE FIELDS
name: accounts-backend-cluster-ip-service
port:
number: 5000
我能够通过执行 skaffold dev
验证 Deployment 已启动并且应用程序 运行。我尝试访问本地主机、127.0.0.1 和 docker 的内部 IP,但无法访问该应用程序。我在浏览器中尝试时连接时间太长,连接被拒绝。
入口的输出描述:
Name: ingress-service
Namespace: default
Address:
Default backend: default-http-backend:80 (<error: endpoints "default-http-backend" not found>)
Rules:
Host Path Backends
---- ---- --------
*
/api/?(.*) accounts-backend-cluster-ip-service:5000 (10.1.0.50:5000,10.1.0.51:5000)
Annotations: kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/rewrite-target: /
nginx.ingress.kubernetes.io/use-regex: true
Events: <none>
默认情况下,skaffold dev
只有port-forwardsuser-definedport-forwards,即explicitly defined in the skaffold.yaml
。例如:
portForward:
- resourceType: deployment
resourceName: accounts-backend-deployment
port: 5000
localPort: 8080
您还可以使用 skaffold dev --port-forward=user,services
port-forward 服务以及任何 user-defined port-forwards.
Skaffold port-forwarding 不包括入口:目前是 cluster-specific。例如,对于 minikube,您需要单独 运行 minikube tunnel
,或者如果使用 nginx-ingress
.
minikube service -n ingress-nginx --url ingress-nginx-controller