首先,我很确定我知道为什么这不起作用:我正在拉取 Dockerpostgres:11-alpine
映像,对其进行修改,然后尝试在自定义映像上更改env:
k8s中的。deployment.yaml
我认为这就是问题所在。
基本上,我正在尝试按照 Dockerpostgres
文档来完成此操作:
docker run --name some-postgres -e POSTGRES_PASSWORD='foo' POSTGRES_USER='bar'
这就是我所拥有的:
Dockerfile.dev
FROM postgres:11-alpine
EXPOSE 5432
COPY ./db/*.sql /docker-entrypoint-initdb.d/
postgres.yaml(在我玩完这个之后,秘密将被移动)
apiVersion: apps/v1
kind: Deployment
metadata:
name: postgres-deployment
spec:
replicas: 1
selector:
matchLabels:
component: postgres
template:
metadata:
labels:
component: postgres
spec:
containers:
- name: postgres
image: testproject/postgres
ports:
- containerPort: 5432
env:
- name: POSTGRES_DB
value: "test_dev"
- name: POSTGRES_USER
value: "bar"
- name: POSTGRES_PASSWORD
value: "foo"
volumeMounts:
- name: postgres-storage
mountPath: /var/lib/postgresql/data
subPath: postgres
volumes:
- name: postgres-storage
persistentVolumeClaim:
claimName: postgres-storage
---
apiVersion: v1
kind: Service
metadata:
name: postgres-cluster-ip-service
spec:
type: ClusterIP
selector:
component: postgres
ports:
- port: 5432
targetPort: 5432
但是,当我使用 Skaffold 在本地启动集群时,env:
“不要使用”,因为我仍然可以使用默认值POSTGRES_USER=postgres
和POSTGRES_PASSWORD=''
.
我敢打赌,如果我这样做了,image: postgres
那么它env:
会起作用,但是我不确定如何做与 Dockerfile 中的等效操作:
COPY ./db/*.sql /docker-entrypoint-initdb.d/
有什么建议么?
如果这也有帮助的skaffold.yaml
话:
apiVersion: skaffold/v1beta15
kind: Config
build:
local:
push: false
artifacts:
- image: testproject/postgres
docker:
dockerfile: ./db/Dockerfile.dev
sync:
manual:
- src: "***/*.sql"
dest: .
- image: testproject/server
docker:
dockerfile: ./server/Dockerfile.dev
sync:
manual:
- src: "***/*.py"
dest: .
deploy:
kubectl:
manifests:
- k8s/ingress.yaml
- k8s/postgres.yaml
- k8s/server.yaml