我是 Kubernetes 的新手,所以假设我对在其中部署应用程序一无所知。
我有一个 Flask 应用程序,我正在尝试从 Azure Pipelines 部署到 GCP Kubernetes 集群。我已经设置了所有环境,但是,当我启动一个新版本(来自 Azure Pipelines)时,我在 GCP Kubernetes 日志屏幕上收到有关我在应用程序中使用的库的导入错误。出现的主要是:
ImportError: cannot import name 'anonymous_user_required' from 'flask_security'
这很奇怪,因为我已经建立了一个虚拟环境,所有的包都在我的本地机器上 requirements.txt
并且一切运行顺利。
下面是我的 Dockerfile:
FROM python:3.7
ENV APP_HOME /app
ENV PORT 5000
WORKDIR $APP_HOME
COPY . $APP_HOME
RUN pip3 install -r requirements.txt
CMD ["python", "app.py"]
还有我的 deployment.yaml:
apiVersion: v1
kind: Service
metadata:
name: app
spec:
ports:
- port: 80
targetPort: 8080
protocol: TCP
name: http
selector:
app: app
type: NodePort
---
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: app
spec:
backend:
serviceName: app
servicePort: 80
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: app
spec:
selector:
matchLabels:
app: app
replicas: 1
template:
metadata:
labels:
app: app
spec:
containers:
- name: app
image: APP_IMAGE
ports:
- containerPort: 8080
livenessProbe: # Used by deployment controller
httpGet:
path: /
port: 8080
initialDelaySeconds: 5
periodSeconds: 5
readinessProbe: # Used by Ingress/GCLB
httpGet:
path: /
port: 8080
initialDelaySeconds: 3
periodSeconds: 5
resources:
limits:
memory: 1024Mi
requests:
memory: 768Mi
正在我的 azure-pipelines.yml 上设置 APP_IMAGE:
steps:
- task: CmdLine@1
displayName: 'Lock image version in deployment.yaml'
inputs:
filename: /bin/bash
arguments: '-c "awk ''{gsub(\"APP_IMAGE\", \"gcr.io/$(DockerImageName):$(Build.BuildId)\", $0); print}'' deployment.yaml > $(build.artifactstagingdirectory)/deployment.yaml"'
我按照 Google 教程将应用程序部署到 Kubernetes 集群。管道工作正常,它在 Google Container Registry 中发布 Docker 镜像,Azure 发布正在 GCP Kubernetes 屏幕上生成日志。
我在 deployment.yaml 文件中遗漏了什么吗?我必须在 GCP Kubernetes 中进行一些额外的配置才能使其工作?