[英]Deploying Django Application with PostgreSQL to Kubernetes Google Cloud cluster
I am having trouble trying to deploy my Django Application and PostgreSQL database to Kubernetes Google Cloud cluster that I've already configured. 我在尝试将Django应用程序和PostgreSQL数据库部署到已经配置的Kubernetes Google Cloud集群时遇到麻烦。
I have successfully created Docker containers for my Django Application and PostgreSQL database. 我已经为Django应用程序和PostgreSQL数据库成功创建了Docker容器。 Here is what my docker-compose.yml file looks like:
这是我的docker-compose.yml文件的样子:
version: '3'
services:
db:
image: postgres
environment:
- POSTGRES_USER=stefan_radonjic
- POSTGRES_PASSWORD=cepajecar995
- POSTGRES_DB=agent_technologies_db
web:
build: .
command: python manage.py runserver 0.0.0.0:8000 --settings=agents.config.docker-settings
volumes:
- .:/agent-technologies
ports:
- "8000:8000"
links:
- db
depends_on:
- db
I have already build the images, and tried sudo docker-compose up
command, and the application works perfectly fine. 我已经构建了映像,并尝试了
sudo docker-compose up
命令,该应用程序运行正常。
After successfully dockerizing Django Application and PostgreSQL, I have tried to configure Deployment / Service YML
files required by Kubernetes, but I am having trouble doing so. 在成功地对Django Application和PostgreSQL进行docker化之后,我尝试配置Kubernetes所需的Deployment / Service
YML
文件,但是这样做很麻烦。 For example: 例如:
deployment-definition.yml - File for deploying Django application: deployment-definition.yml-用于部署Django应用程序的文件:
apiVersion: apps/v1
kind: Deployment
metadata:
name: agent-technologies-deployment
labels:
app: agent-technologies
tier: backend
spec:
template:
metadata:
name: agent-technologies-pod
labels:
app: agent-technologies
tier: backend
spec:
containers:
- name:
image:
ports:
- containerPort: 8000
replicas:
selector:
matchLabels:
tier: backend
Inside container list of dictionaries, I know that my container name should be web
, but I am not sure where the image of that container is located so I do not know what should i specify as container image. 在字典的容器列表中,我知道我的容器名称应该是
web
,但是我不确定该容器的图像位于何处,所以我不知道我应该指定什么作为容器图像。
Another problem lies in postgres/deployment-definition.yml : 另一个问题在于postgres / deployment-definition.yml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: postgres
spec:
replicas: 1
selector:
matchLabels:
app: postgres-container
template:
metadata:
labels:
app: postgres-container
tier: backend
spec:
containers:
- name: postgres-container
image: postgres:9.6.6
env:
- name: POSTGRES_USER
valueFrom:
secretKeyRef:
name: postgres-credentials
key: user
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: postgres-credentials
key: password
- name: POSTGRES_DB
value: agent_technologies_db
ports:
- containerPort: 5432
volumeMounts:
- name: postgres-volume-mount
mountPath: /var/lib/postgresql/data
volumes:
- name: postgres-volume-mount
persistentVolumeClaim:
claimName: postgres-pvc
I do not understand what volumeMounts
and volumes
are for, and if i even specified them correctly. 我不明白什么是
volumeMounts
和volumes
,以及是否正确指定了它们。
Here is my secret-definition.yml file: 这是我的secret-definition.yml文件:
apiVersion: v1
kind: Secret
metadata:
name: postgres-credentials
type: Opaque
data:
user: stefan_radonjic
passowrd: cepajecar995
My postgres/service-definition.yml file: 我的postgres / service-definition.yml文件:
apiVersion: v1
kind: Service
metadata:
name: postgres-service
spec:
selector:
app: postgres-container
ports:
- protocol: TCP
port: 5432
targetPort: 5432
My postgres/volume-definition.yml file: 我的postgres / volume-definition.yml文件:
apiVersion: v1
kind: PersistentVolume
metadata:
name: postgres-pv
labels:
type: local
spec:
capacity:
storage: 2Gi
storageClassName: standard
accessModes:
- ReadWriteMany
hostPath:
path: /data/postgres-pv
And my postgres/volume-claim-definitono.yml file: 还有我的postgres / volume-claim-definitono.yml文件:
apiVersion: v1
kind: PersistentVolume
metadata:
name: postgres-pv
labels:
type: local
spec:
capacity:
storage: 2Gi
storageClassName: standard
accessModes:
- ReadWriteMany
hostPath:
path: /data/postgres-pv
Last but not least, my service-definition.yml file - for Django application 最后但并非最不重要的一点是,我的service-definition.yml文件-适用于Django应用程序
apiVersion: v1
kind: Service
metadata:
name: agent-technologies-service
spec:
selector:
app: agent-technologies
ports:
- protocol: TCP
port: 8000
targetPort: 8000
type: NodePort
Besides the questions I have already asked above, I also want to ask am I doing this right? 除了上面已经问过的问题之外,我还想问一下我在做这个对吗? If not, what can I do to fix this.
如果没有,我该怎么做才能解决此问题。
Inside container list of dictionaries, I know that my container name should be web, but I am not sure where the image of that container is located so I do not know what should i specify as container image.
在字典的容器列表中,我知道我的容器名称应该是web,但是我不确定该容器的图像位于何处,所以我不知道我应该指定什么作为容器图像。
Name for container is local to the pod (you can have several containers sharing same pod). 容器的名称是容器的本地名称(您可以有多个容器共享同一容器)。 Container name (web in your case) is for your files given under deployment:
容器名称(在您的情况下为Web)是针对在部署下给出的文件的:
# setting name of first container within pod to web spec: containers: - name: web
I do not understand what volumeMounts and volumes are for, and if i even specified them correctly.
我不明白什么是volumeMount和卷,以及是否正确指定了它们。
Besides the questions I have already asked above, I also want to ask am I doing this right?
除了上面已经问过的问题之外,我还想问一下我在做这个对吗? If not, what can I do to fix this.
如果没有,我该怎么做才能解决此问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.