我正在尝试弄清楚如何使用 Kubernetes 部署我的应用程序,但是我已经有几年没有触碰它了,所以,我没有忘记的那点东西似乎已经发生了变化。
我创建了一个deployment.yaml
并部署了它,但正如预期的那样,它无法启动。我做了一些改进,重建了 Docker 映像,推送了它,将指向更改deployment.yaml
为新映像并重新应用它:
kubectl apply -f deployment.yml
现在,我看到了这个:
> kubectl.exe get pods
NAME READY STATUS RESTARTS AGE
recruiters-wtf-665f58f994-tsf6l 1/2 CrashLoopBackOff 19 77m
recruiters-wtf-6f994cc5b9-9rj28 0/2 Pending 0 7m46s
为什么新的豆荚不取代旧的豆荚呢?
我的deployment.yaml
样子是这样的:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: recruiters-wtf
labels:
app: recruiters-wtf
spec:
replicas: 1
selector:
matchLabels:
app: recruiters-wtf
template:
metadata:
labels:
app: recruiters-wtf
spec:
containers:
- name: recruiters-wtf
image: eu.gcr.io/recruiters-wtf/recruiters-wtf:edda1a5626d1
ports:
- containerPort: 80
# The following environment variables will contain the database host,
# user and password to connect to the PostgreSQL instance.
env:
- name: POSTGRES_DB_HOST
value: 127.0.0.1:5432
# [START cloudsql_secrets]
- name: POSTGRES_DB_USER
valueFrom:
secretKeyRef:
name: cloudsql-db-credentials
key: username
- name: POSTGRES_DB_PASSWORD
valueFrom:
secretKeyRef:
name: cloudsql-db-credentials
key: password
# [END cloudsql_secrets]
# Change <INSTANCE_CONNECTION_NAME> here to include your GCP
# project, the region of your Cloud SQL instance and the name
# of your Cloud SQL instance. The format is
# $PROJECT:$REGION:$INSTANCE
# [START proxy_container]
- name: cloudsql-proxy
image: gcr.io/cloudsql-docker/gce-proxy:1.14
command: ["/cloud_sql_proxy", "-instances=<INSTANCE_CONNECTION_NAME>=tcp:5432",
# If running on a VPC, the Cloud SQL proxy can connect via Private IP. See:
# https://cloud.google.com/sql/docs/mysql/private-ip for more info.
# "-ip_address_types=PRIVATE",
"-credential_file=/secrets/cloudsql/credentials.json"]
# [START cloudsql_security_context]
securityContext:
runAsUser: 2 # non-root user
allowPrivilegeEscalation: false
# [END cloudsql_security_context]
volumeMounts:
- name: cloudsql-instance-credentials
mountPath: /secrets/cloudsql
readOnly: true
# [END proxy_container]
# [START volumes]
volumes:
- name: cloudsql-instance-credentials
secret:
secretName: cloudsql-instance-credentials
# [END volumes]