0

Below is the postgres service file that defines both service and deployment of postgres service. However the postgres service keeps restarting every minute. Could anyone help me to understand why it keeps restaring? I'm running yaml file on Minikube (1.18)

apiVersion: v1
kind: Service
metadata:
  name: postgresdb
  labels:
    app: postgresdb
spec:
  ports:
  - port: 5432
    name: tcp
  selector:
    app: postgresdb
  type: ClusterIP
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: postgresdb-v1
  labels:
    app: postgresdb
    version: v1
spec:
  replicas: 1
  selector:
    matchLabels:
      app: postgresdb
      version: v1
  template:
    metadata:
      labels:
        app: postgresdb
        version: v1
    spec:
      containers:
      - name: postgresdb
        image: postgres
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 5432
        env:
          - name: POSTGRES_DB
            value: simple-service 
          - name: POSTGRES_USER
            value: user
          - name: POSTGRES_PASSWORD
            value: pass
        readinessProbe:
          exec:
            command: ["psql", "-P", "pass", "-U", "user", "-d", "simple-service", "-c", "SELECT 1"]
          initialDelaySeconds: 15
          timeoutSeconds: 2
        livenessProbe:
          exec:
            command: ["psql", "-P", "pass", "-U", "user", "-d", "simple-service", "-c", "SELECT 1"]
          initialDelaySeconds: 45
          timeoutSeconds: 2
                
---
2
  • What do kubectl logs of the failing pods say? Commented Jul 27, 2020 at 10:52
  • Hi David, I forgot to specify the "-W", "pass" in execute command. It is working now. Thanks for your time Commented Jul 27, 2020 at 11:30

1 Answer 1

5

Your readiness probe is failing because of invalid flag in script. To pass the password via command line use -W or --password check doc here

So your probe should be as below (both readiness and liveliness probe)

command: ["psql", "--password", "pass", "-U", "user", "-d", "simple-service", "-c", "SELECT 1"]
Sign up to request clarification or add additional context in comments.

4 Comments

I tried the command you shared, however it still keeps restarting
I misspelled password , if you copied then there would be error. If not then share output of kubectl describe po <podName>
It worked!! Initially I used --password It didn't work. I used -W it is working now :) Thank you Tarun for all the help !!
@SwetaSharma please update the status of question if it's worked mark answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.