Volume Mounting in Kubernetes Pods using Kind

114 Views Asked by At

Community, I need your assistance regarding an issue with mounting volumes to pods in Kubernetes using Kind. Here's my Kind configuration:

kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4

kubeadmConfigPatches:
- |
  apiVersion: kubelet.config.k8s.io/v1beta1
  kind: KubeletConfiguration
  evictionHard:
    nodefs.available: "0%"

kubeadmConfigPatchesJSON6902:
- group: kubeadm.k8s.io
  version: v1beta3
  kind: ClusterConfiguration
  patch: |
    - op: add
      path: /apiServer/certSANs/-
      value: my-hostname

nodes:
- role: control-plane
  extraPortMappings:
  - containerPort: 31000
    hostPort: 31000
  extraMounts:
  - hostPath: /home/dyedfox/volumes/db
    containerPath: /db
  - hostPath: /home/dyedfox/volumes/secret1
    containerPath: /secret1
  - hostPath: /home/dyedfox/volumes/secret2
    containerPath: /secret2
  - hostPath: /home/dyedfox/volumes/secret3
    containerPath: /secret3

- role: worker
- role: worker

And here's my deployment:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: iam-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: iam-app
  template:
    metadata:
      labels:
        app: iam-app
    spec:
      containers:
      - name: iam-app
        image: dyedfox/iam-app:latest
        env:
        ports:
        - containerPort: 5000
        volumeMounts:
        - name: iam-db
          mountPath: /app/db
      volumes:
      - name: iam-db
        hostPath:
          path: /db
---
apiVersion: v1
kind: Service
metadata:
  name: iam-app
  labels:
    app: iam-app
spec:
  type: NodePort
  ports:
  - port: 5000
    targetPort: 5000
    nodePort: 31000
  selector:
    app: iam-app

Here is the output of kubectl describe <pod> command:

Name:             iam-deployment-7b65449dff-qwqbf
Namespace:        default
Priority:         0
Service Account:  default
Node:             kind-worker2/172.21.0.2
Start Time:       Tue, 19 Dec 2023 10:22:27 +0200
Labels:           app=iam-app
                  pod-template-hash=7b65449dff
Annotations:      <none>
Status:           Running
IP:               10.244.2.3
IPs:
  IP:           10.244.2.3
Controlled By:  ReplicaSet/iam-deployment-7b65449dff
Containers:
  iam-app:
    Container ID:   containerd://ed50dd88df3e0aae41e711cfe6027d559fa61fb16766c5313c1001400942aa78
    Image:          dyedfox/iam-app:latest
    Image ID:       docker.io/dyedfox/iam-app@sha256:45bca58157400a426acabb0dba6637b154a7e19762617fc9f173607ee21c2cfb
    Port:           5000/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Tue, 19 Dec 2023 10:25:09 +0200
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /app/db from iam-db (rw)
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-977c8 (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             True 
  ContainersReady   True 
  PodScheduled      True 
Volumes:
  iam-db:
    Type:          HostPath (bare host directory volume)
    Path:          /db
    HostPathType:  
  kube-api-access-977c8:
    Type:                    Projected (a volume that contains injected data from multiple sources)
    TokenExpirationSeconds:  3607
    ConfigMapName:           kube-root-ca.crt
    ConfigMapOptional:       <nil>
    DownwardAPI:             true
QoS Class:                   BestEffort
Node-Selectors:              <none>
Tolerations:                 node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                             node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:                      <none>

The problem I'm facing is that these volumes are being mounted in the Kind control plane container but not in the pods themselves (directory is not being created). /app is app working directory. I am not receiving any error messages in either the kind-control-plane container or the application pod. Can you help me figure out what might be causing this issue? Thanks in advance.

0

There are 0 best solutions below