python - 'OSError: [Errno 98] Address already in use' 在 kubernetes 上部署
问题描述
我正在尝试使用 Python 的 Flask API 在 Google Kubernetes Engine 上部署 Python 应用程序。部署应用程序后,我遇到了“OSError:[Errno 98] 地址已在使用中”。
我认为错误可能是由于端口号,我尝试更改 gunicorn 配置文件上的端口号,但仍然遇到同样的问题。
这些是我正在使用 gunicorn_config.py 的文件
import multiprocessing
bind = "0.0.0.0:8000"
workers = multiprocessing.cpu_count() * 2 + 1
accesslog = "-" # STDOUT
access_log_format = '%(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s"'
loglevel = "debug"
capture_output = True
enable_stdio_inheritance = True
以下是我用来部署应用程序的 Dockerfile:
# python runtime
FROM ubuntu as intermediate
# install git
RUN apt-get update
RUN apt-get install -y git
# add credentials on build
ARG ACCESS_TOKEN
RUN git config --global url."https://${ACCESS_TOKEN}:@github.com/".insteadOf "https://github.com/"
ARG BRANCH
RUN git clone https://github.com/org_name/rest_api.git -b "${BRANCH}"
FROM python:3.6-stretch
# copy the repository form the previous image
COPY --from=intermediate rest_api rest_api
# working directory
WORKDIR /rest_api/id_generation
# install requirements
RUN pip3 install -r ./src/requirements.txt
# make port 8000 available to the world outside
EXPOSE 8000
CMD ["gunicorn", "--config", "./conf/gunicorn_config.py", "src.main:app"]
这是我用来在 Kuberenetes Engine 上部署的 Kubernetes 命令
kubectl run deployment_name --image-pull-policy=Always --overrides='
{
"apiVersion": "apps/v1beta1",
"kind": "Deployment",
"metadata": {
"name": "deployment_name",
"labels": {
"app": "deployment_name"
}
},
"spec": {
"selector": {
"matchLabels": {
"app": "deployment_name"
}
},
"template": {
"metadata": {
"labels": {
"app": "deployment_name"
}
},
"spec": {
"containers": [
{
"name": "deployment_name",
"image": "gcr.io/project_name/id_generator:development",
"imagePullPolicy": "Always",
"ports": [
{
"containerPort": 8000
}
],
"volumeMounts": [
{
"name": "credentials",
"readOnly": true,
"mountPath":"/rest_api/keys"
}
],
"env":[
{
"name":"GOOGLE_APPLICATION_CREDENTIALS",
"value":"/rest_api/keys/key.json"
},
{
"name":"ENVIRONMENT",
"value":"development"
}
]
}
],
"volumes": [
{
"name": "credentials",
"secret": {
"secretName": "credentials"
}
}
]
}
}
}
}
' --image=gcr.io/project_name/deployment_name:development --port 8000
我该如何解决这个错误?
解决方案
推荐阅读
- java - 在 Android Studio 中使用 Google Places API 时找不到汽车修理店/车库/汽车店
- c++ - 有没有一种可能的方法将 for 循环结果返回到像三元运算符这样的函数中?
- c# - 具有多行的 WPF 水平 ListView
- android - Android 应用内结算 - 如何处理退款
- ios - 如何使用 swift 在 Firebase Cloud Firestore 中获取文档的位置?
- python-3.x - for循环中的Lambda函数在tkinter中绑定关键字
- javascript - Web App 在 Webview 中运行并像原生 App 一样安装
- angular - 如何在使用jspdf-autotable创建的pdf中的表格之前插入文本
- google-app-engine - Bad Gateway 502 - Google App Engine - [CRITICAL] 工作人员超时
- c# - C#让一个类返回它的实例而不使用函数或变量