以下を実行するだけ!!
cat <<EOF | kubectl apply -f-
apiVersion: v1
kind: Secret
metadata:
name: postgres-password
type: Opaque
data:
password: dGVzdA==
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: postgres
spec:
selector:
matchLabels:
app: postgres
template:
metadata:
labels:
app: postgres
spec:
containers:
- name: postgres
image: postgres:13-alpine
env:
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: postgres-password
key: password
ports:
- containerPort: 5432
---
apiVersion: v1
kind: Service
metadata:
name: postgres
spec:
selector:
app: postgres
ports:
- port: 5432
targetPort: 5432
postgresへのログイン方法
$ kubectl get po | grep postgres | awk '{print $1}'
$ kubectl exec -it [表示されたpostgres pod] sh
$ psql -U posgres
# postgres