Report this

What is the reason for this report?

How to fix "DOBS Pod Owner" linter error in an existing kubernetes cluster

Posted on April 14, 2021

I was hoping to upgrade my DigitalOcean kubernetes cluster, but have the following linting error: https://docs.digitalocean.com/products/kubernetes/resources/clusterlint-errors/#dobs-pod-owner

I followed a tutorial at the time which did NOT set up a StatefulSet for my PVC, which is why I am getting this error.

I have the following files:

# postgres-storage.yml

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: postgres-pv-claim
  labels:
    app: postgres
spec:
  storageClassName: do-block-storage
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi

and

# postgres.yml

apiVersion: v1
kind: Service
metadata:
  name: postgres
  labels:
    app: postgres
spec:
  ports:
   - port: 5432
  selector:
   app: postgres
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: postgres
spec:
  selector:
    matchLabels:
      app: postgres
  replicas: 1
  template:
    metadata:
      labels:
        app: postgres
    spec:
      containers:
        - name: postgres
          image: postgres:9.6
          imagePullPolicy: "IfNotPresent"
          ports:
            - containerPort: 5432
          env:
            - name: POSTGRES_USER
              valueFrom:
                secretKeyRef:
                  name: postgres-credentials
                  key: POSTGRES_USER
            - name: POSTGRES_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: postgres-credentials
                  key: POSTGRES_PASSWORD
          volumeMounts:
            - mountPath: /var/lib/postgresql/data
              name: postgredb
              subPath: postgres
      volumes:
        - name: postgredb
          persistentVolumeClaim:
            claimName: postgres-pv-claim

I would like to upgrade my cluster, but am unsure how to fix this issue without breaking postgres.

The example (https://docs.digitalocean.com/products/kubernetes/how-to/add-volumes/) seems to add a StatefulSet with a busybox image, so should I just use my postgres image here instead?

I guess what I am a bit confused by is the example under Define the Pod looks like what I want in my postgres.yml, but then I don’t know how to set up the StatefulSet from above without all the busybox stuff (since I assume I no longer want my postgres there).



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hey!

To fix the “DOBS Pod Owner” linter error in your DigitalOcean Kubernetes cluster, you should transition your PostgreSQL deployment to use a StatefulSet instead of a Deployment. StatefulSets are ideal for stateful applications like databases, as they provide stable and unique network identifiers, stable persistent storage, and ordered, graceful deployment and scaling.

Here’s how you can modify your existing setup to use a StatefulSet:

  1. Convert Deployment to StatefulSet: You need to change your postgres.yml to define a StatefulSet instead of a Deployment for your PostgreSQL database.
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: postgres
spec:
  serviceName: "postgres"
  replicas: 1
  selector:
    matchLabels:
      app: postgres
  template:
    metadata:
      labels:
        app: postgres
    spec:
      containers:
      - name: postgres
        image: postgres:9.6
        ports:
        - containerPort: 5432
        volumeMounts:
        - name: postgredb
          mountPath: /var/lib/postgresql/data
        env:
          - name: POSTGRES_USER
            valueFrom:
              secretKeyRef:
                name: postgres-credentials
                key: POSTGRES_USER
          - name: POSTGRES_PASSWORD
            valueFrom:
              secretKeyRef:
                name: postgres-credentials
                key: POSTGRES_PASSWORD
  volumeClaimTemplates:
  - metadata:
      name: postgredb
    spec:
      accessModes: [ "ReadWriteOnce" ]
      storageClassName: "do-block-storage"
      resources:
        requests:
          storage: 1Gi
  1. Apply the updated postgres.yml file with kubectl apply -f postgres.yml. Ensure you handle the existing data and PVCs carefully to avoid data loss.

  2. Check that the StatefulSet and its pods are running correctly using kubectl get statefulset and kubectl get pods.

By transitioning to a StatefulSet, you align with the Kubernetes best practices for managing stateful applications and resolve the DOBS Pod Owner linter error.

Suggestion: Considering your use case involves managing a PostgreSQL database within Kubernetes, you might want to explore using DigitalOcean’s Managed Database clusters. By using a managed database, you offload the operational overhead of managing, scaling, and securing your database to DigitalOcean. This service provides automated backups, easy scaling, and high availability, allowing you to focus more on your application development rather than on database management:

https://www.digitalocean.com/products/managed-databases-postgresql

Best,

Bobby

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.