gpt4 book ai didi

kubernetes - 从 kubernetes pod 开放端口获取连接被拒绝

转载 作者:行者123 更新时间:2023-12-02 11:55:24 24 4
gpt4 key购买 nike

我是 kubernetes 的新手,我正在尝试将带有 Gitlab 管道的 MEAN 堆栈应用程序部署到 Google Cloud 中的 Kubernetes Engine。但是,我无法让它连接到在开放端口(4200)上运行我的代码的 pod。你可以在下面找到我的 YAML 配置。
Dockerfile

FROM node:13.13-alpine
RUN mkdir -p /usr/src/app
COPY . /usr/src/app
WORKDIR /usr/src/app
RUN cd /usr/src/app && npm install @angular/core@9.1.4 @angular/animations@9.1.4 @angular/common@9.1.4 @angular/forms@9.1.4 @angular/platform-browser@9.1.4 @angular/router@9.1.4 @angular/platform-browser-dynamic@9.1.4 @angular/compiler@9.1.4 @angular/compiler-cli@9.1.4 @angular/language-service@9.1.4 && npm install && npm run-script build
EXPOSE 3000 4200
CMD ["npm","run-script","start"]

Gitlab-ci.yml
deploy service:
stage: deploy_kubernetes
image: google/cloud-sdk:latest
script:
# Auth and GC Cluster configs
- echo $GKE_SERVICE_KEY | base64 -d > service-account.json
- gcloud auth activate-service-account --key-file service-account.json
- gcloud container clusters get-credentials $GKE_cluster_name --zone $GKE_zone --project $GKE_project_id
# Kompose to build deployment files
- curl -L https://github.com/kubernetes/kompose/releases/download/v1.19.0/kompose-linux-amd64 -o kompose
- chmod +x kompose
- mv ./kompose /usr/local/bin/kompose
- kompose convert -f deploy/docker-compose-stack.yml
# Kompose patches and service creating in Kubernetes
- kubectl apply -f mean-deployment.yaml,mean-service.yaml
- echo $PATCH_LOAD_BALANCER | base64 -d > patch_load_balancer.json
- kubectl patch svc mean --patch "$(cat patch_load_balancer.json)"

docker-compose-stack.yml
version: "3.7"
services:
mean:
image: theycallmefox/gp_ips:latest
ports:
- 3000:3000
- 4200:4200

运行 kubectl get svc --all-namespaces 得到以下输出:
NAMESPACE     NAME                   TYPE           CLUSTER-IP    EXTERNAL-IP    PORT(S)                                                    AGE
default kubernetes ClusterIP 10.0.0.1 <none> 443/TCP 3d
default mean LoadBalancer 10.0.12.199 34.91.94.183 443:31324/TCP,80:32732/TCP,3000:32577/TCP,4200:32512/TCP 2d2h
kube-system default-http-backend NodePort 10.0.4.122 <none> 80:32038/TCP 2d23h
kube-system kube-dns ClusterIP 10.0.0.10 <none> 53/UDP,53/TCP 2d23h
kube-system metrics-server ClusterIP 10.0.1.220 <none> 443/TCP 2d23h

最后,运行 kubectl 日志 -f mean-6cb9949f77-kbz95
> portal-ips@0.0.0 start /usr/src/app
> ng serve && cd ../backend && node app.js
chunk {main} main.js, main.js.map (main) 412 kB [initial] [rendered]
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 141 kB [initial] [rendered]
chunk {runtime} runtime.js, runtime.js.map (runtime) 6.15 kB [entry] [rendered]
chunk {scripts} scripts.js, scripts.js.map (scripts) 219 kB [entry] [rendered]
chunk {styles} styles.js, styles.js.map (styles) 1.12 MB [initial] [rendered]
chunk {vendor} vendor.js, vendor.js.map (vendor) 5.6 MB [initial] [rendered]
Date: 2020-05-24T17:50:28.305Z - Hash: a02a05a0d81f690bca61 - Time: 35281ms
** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
: Compiled successfully.

有任何想法吗?谢谢。

最佳答案

您的应用程序正在监听 localhost,而您的负载均衡器将流量转发到以太网网络接口(interface)。

您需要更改您的应用程序并使其在 0.0.0.0 上提供服务.

关于kubernetes - 从 kubernetes pod 开放端口获取连接被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61991464/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com