Postgres user not created Kubernetes

9/29/2018

I have the following YAML file for create a postgres server instance

kind: Deployment
apiVersion: apps/v1beta1
metadata: 
 name: spring-demo-db
 labels: 
  app: spring-demo-application
spec: 
 replicas: 1
 selector: 
  matchLabels: 
   app: spring-demo-db
 template: 
  metadata: 
   creationTimestamp: null
   labels: 
    app: spring-demo-db
  spec: 
   containers: 
    - name: spring-demo-db
      image: postgres:10.4
      ports: 
      - name: spring-demo-db
        containerPort: 5432
        protocol: TCP
      env: 
      - name: POSTGRES_PASSWORD
        value: "springdemo"
      - name: POSTGRES_USER
        value: "springdemo"
      - name: POSTGRES_DB
        value: "springdemo"
      volumeMounts:
            - mountPath: /var/lib/postgresql/data
              name: postgres-storage
      terminationMessagePath: /dev/termination-log
      terminationMessagePolicy: File
      imagePullPolicy: IfNotPresent
   volumes: 
    - name: "postgres-storage"
      persistentVolumeClaim: 
       claimName: spring-demo-pv-claim   
   restartPolicy: Always

But when ssh into the container user springdemo not created. I have been struggling all day.What could be the problem for this

Anyone who can help me?

-- Navigator
kubernetes
postgresql
yaml

1 Answer

9/29/2018

You didn't mention what command you're running and what error you're getting, so I'm guessing here, but try this:

kind: Deployment
apiVersion: apps/v1beta1
metadata: 
 name: spring-demo-db
 labels: 
  app: spring-demo-application
spec: 
 replicas: 1
 selector: 
  matchLabels: 
   app: spring-demo-db
 template: 
  metadata: 
   creationTimestamp: null
   labels: 
    app: spring-demo-db
  spec: 
   containers: 
    - name: spring-demo-db
      image: postgres:10.4
      ports: 
      - name: spring-demo-db
        containerPort: 5432
        protocol: TCP
      env: 
      - name: POSTGRES_USER
        value: "springdemo"
      - name: POSTGRES_DB
        value: "springdemo"
      - name: POSTGRES_PASSWORD
        value: "springdemo"
      volumeMounts:
            - mountPath: /var/lib/postgresql/data
              name: postgres-storage
      terminationMessagePath: /dev/termination-log
      terminationMessagePolicy: File
      imagePullPolicy: IfNotPresent
   volumes: 
    - name: "postgres-storage"
      persistentVolumeClaim: 
       claimName: spring-demo-pv-claim   
   restartPolicy: Always

But if it doesn't work, just use the Helm chart, because, among other issues, you are passing the password in an insecure way, which is a bad idea.

-- samhain1138
Source: StackOverflow