kubernetes 正在暴露未聲明的端口 (kubernetes is exposing not declared port)


問題描述

kubernetes 正在暴露未聲明的端口 (kubernetes is exposing not declared port)

我沒有在 kubernetes/docker 中公開任何端口,但我仍然能夠從另一個 pod 連接到 python 應用程序。

這是 Dockerfile

FROM python:3.6.8
.
.
.
.

RUN chmod u+x /app/entrypoint.sh
ENTRYPOINT /app/entrypoint.sh $WORKERS $FLASK_APP

這是入口點

flask db upgrade ‑d abc/migration
gunicorn ‑w $1 ‑k gevent ‑b 0.0.0.0:7103 $2

這是deployment.yaml

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
 labels:
   app: nw‑microservice  
 name: nw‑microservice  
 namespace: nw‑microservice‑stg 
spec:
 replicas: 1
 strategy:
   rollingUpdate:
     maxSurge: 20%
     maxUnavailable: 0
   type: RollingUpdate
 template:
   metadata:
     labels:
       app: nw‑microservice  
   spec:
     containers:
       ‑ env:
           ‑ name: "PYTHONPATH"
             value: "/app"
         image: imageurl
         imagePullPolicy: IfNotPresent
         name: nw‑microservice‑api  
         terminationMessagePath: /dev/termination‑log
         terminationMessagePolicy: File
     dnsPolicy: ClusterFirst
     imagePullSecrets:
       ‑ name: shared‑account‑ecr
     restartPolicy: Always

這是服務

apiVersion: v1
kind: Service
metadata:
 name: service  
 namespace: namespace  
spec:
 ports:
   ‑ name: http
     port: 7103  
     protocol: TCP
     targetPort: 7103
 selector:
   app: nw‑microservice  
 type: ClusterIP

所以我可以通過http://service.namespace:7103 但我不明白為什麼。


參考解法

方法 1:

The ports defined in a container are purely informational:

Exposing a port here gives the system additional information about the network connections a container uses, but is primarily informational. Not specifying a port here DOES NOT prevent that port from being exposed. Any port which is listening on the default "0.0.0.0" address inside a container will be accessible from the network.

You can have a look here

(by mggITChap)

參考文件

  1. kubernetes is exposing not declared port (CC BY‑SA 2.5/3.0/4.0)

#gunicorn #port #Kubernetes #deployment






相關問題

Heroku 無法啟動我的應用程序,但 `foreman start` 工作 (Heroku fails to start my app, but `foreman start` works)

為什麼不再推薦 gunicorn_django ? (Why is gunicorn_django not recommended anymore?)

Supervisord 拋出錯誤:“無法執行 /var/application/gunicorn_start:ENOEXEC” (Supervisord throws error: "couldn't exec /var/application/gunicorn_start: ENOEXEC")

服務器上更改的 HTML 文件未反映 (The HTML file changed on server is not reflected)

在 gae flexible 上長時間運行的雲任務會提前終止而不會出錯。如何調試?我錯過了什麼? (Long running cloud task on gae flexible terminates early without error. How to debug? What am I missing?)

Gunicorn 沒有自動啟動 (Gunicorn not starting automatically)

nginx的配置文件中的主機名未知? (Hostname in configfile of nginx unkown?)

重新啟動 gunicorn 和 nginx 不會反映拉取請求後的更改 (restarting gunicorn and nginx doesn't reflect changes after pull request)

當 gunicorn / celery 服務重新啟動時,Django 中有沒有辦法只執行一次 python 代碼? (Is there a way in Django to execute some python code only once when gunicorn / celery services are getting restarted?)

ModuleNotFoundError:在 Heroku 服務器上使用 Django 和 Gunicorn 時沒有名為“App Name”的模塊 (ModuleNotFoundError: No module named 'App Name' when using Django and Gunicorn on a heroku server)

kubernetes 正在暴露未聲明的端口 (kubernetes is exposing not declared port)

PM2.js 在 Virtualenv/Anaconda 環境中運行 Gunicorn/Flask 應用程序 (PM2.js to Run Gunicorn/Flask App inside Virtualenv/Anaconda env)







留言討論