0

I want mount azure disk to azure Kubernetes for PostgreSQL pod. My yml files

postgres-storage.yaml

apiVersion: v1
kind: PersistentVolume
metadata:
  name: postgres-pv
spec:
  capacity:
    storage: 80Gi
  storageClassName: manual
  volumeMode: Filesystem
  accessModes:
    - ReadWriteOnce
  azureDisk:
    kind: Managed
    diskName: es-us-dev-core-test
    diskURI: /subscriptions/id/resourceGroups/kubernetes_resources_group/providers/Microsoft.Compute/disks/dev-test
    

---

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: postgres-pv-claim
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 80Gi

postgres-configmap.yaml

apiVersion: v1
kind: ConfigMap
metadata:
  name: postgres-config
  labels:
    app: postgres
data:
  POSTGRES_DB: dev-test
  POSTGRES_USER: admintpost
  POSTGRES_PASSWORD: ada3dassasa

StatefulSet.yml


apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: postgres-statefulset
  labels:
    app: postgres
spec:
  serviceName: "postgres"
  replicas: 1
  selector:
    matchLabels:
      app: postgres
  template:
    metadata:
      labels:
        app: postgres
    spec:
      containers:
      - name: postgres
        image: postgres:12
        envFrom:
        - configMapRef:
            name: postgres-config
        ports:
        - containerPort: 5432
          name: postgresdb
        volumeMounts:
        - name: pv-data
          mountPath: /var/lib/postgresql/data
      volumes:
      - name: pv-data
        persistentVolumeClaim:
          claimName: postgres-pv-claim

Instruction for create disk https://learn.microsoft.com/en-us/azure/aks/azure-disk-volume

I get an error that it cannot connect to the disk, could you please tell me how to add Azure Disk to the pod.Thanks.

  • Make sure that the cluster has contributor permissions on the disk. Either provision the disk in the MC_ resource group (which has permissions by default), or assign contributor permissions on the disk to the AKS cluster service principal/managed identity. – mmking Dec 17 '20 at 21:27
  • Can you share the screenshot of the error? – Charles Xu Dec 18 '20 at 07:56
  • Does this answer your question? [Permissions error when attaching Azure Disk to AKS pod](https://stackoverflow.com/questions/62614458/permissions-error-when-attaching-azure-disk-to-aks-pod) – mmking Dec 18 '20 at 16:14

1 Answers1

0

Create Azure Disk in the correct resource group

Looking at the file postgres-storage.yaml:

in spec.azureDisk.diskURI I see that you have created the disk in the resource group kubernetes_resources_group. However, you should create the disk inside a resource group whose name is something like this: MC_kubernetes_resources_group_<your cluster name>_<region of the cluster>

Make sure that you create the disk in the same availability zone as your cluster.

Set caching mode to None

In the file postgres-storage.yaml:

set spec.azureDisk.cachingMode to None

Fix the definition of StatefulSet.yml

If you're using Azure Disks then in the file StatefulSet.yml:

in spec.template.spec you should replace the following:

volumeMounts:
  - name: pv-data
    mountPath: /var/lib/postgresql/data

with the this:

volumeMounts:
  - name: pv-data
    mountPath: /var/lib/postgresql/data
    subPath: pgdata

EDIT: fixed some mistakes in the last part.

Rehan Rajput
  • 112
  • 8