1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【k8s】一分でpostgresql環境を作る!!

Last updated at Posted at 2021-07-09

以下を実行するだけ!!

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
1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?