2

I am migrating an application that consists of 1 or more tomcat servers and 1 or more wildfly servers to k8s. I have it up and working with a deployments for tomcat and wildfly with a clusterIP for each. I am now trying to combine log files from the multiple nodes into a single log directory on the host (for now single host deployment). I have created a PVC with the following yaml files:

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: local-storage
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer
reclaimPolicy: Delete

apiVersion: v1
kind: PersistentVolume
metadata:
  name: local-pv
spec:
  storageClassName: local-storage
  capacity:
    storage: 10Gi
  accessModes:
  - ReadWriteMany
  persistentVolumeReclaimPolicy: Retain
  hostPath:
    path: /C/k8s/local-pv/logs

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: local-claim
spec:
  accessModes:
  - ReadWriteMany
  storageClassName: local-storage
  resources:
    requests:
      storage: 2Gi

I have the tomcat deployment mapped to the voles by:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: tomcat-deployment
spec:
  replicas: 2
  selector:
    matchLabels:
      component: tomcat-deployment
  template:
    metadata:
      labels:
        component: tomcat
    spec:
      initContainers:
      - name: volume-mount-hack
        image: busybox
        command: ["sh", "-c", "chmod -R 777 /usr/local/tomcat/logs"]
        volumeMounts:
        - name: local-persistent-storage
          mountPath: /usr/local/tomcat/logs
      containers:
        - name: tomcat
          image: tomcat-full:latest 
          volumeMounts:
          - name: local-persistent-storage
            mountPath: /usr/local/tomcat/logs
            subPath: tomcat  
      volumes:
          - name: local-persistent-storage
            persistentVolumeClaim:
              claimName: local-claim

I startup all the components and the system is functioning as expected. However, when I look in the host directory C/k8s/local-pv/logs/tomcat, no files are showing. I connect to the tomcat pod with docker exec and I see the log files from both tomcat servers. The files shown in the /usr/local/tomcat/logs survive a deployment restart so I know they are written somewhere. I searched my entire hard drive and the files are not anywhere.

I checked the pvc, pv, and storage class

kubectl describe pvc local-claim
Name:          local-claim
Namespace:     default
StorageClass:  local-storage
Status:        Bound
Volume:        local-pv
Labels:        <none>
Annotations:   pv.kubernetes.io/bind-completed: yes
               pv.kubernetes.io/bound-by-controller: yes
Finalizers:    [kubernetes.io/pvc-protection]
Capacity:      10Gi
Access Modes:  RWX
VolumeMode:    Filesystem
Mounted By:    tomcat-deployment-644698fdc6-jmxz9
               tomcat-deployment-644698fdc6-qvx9s
Events:
  Type    Reason                Age                From                         Message
  ----    ------                ----               ----                         -------
  Normal  WaitForFirstConsumer  12m (x3 over 14m)  persistentvolume-controller  waiting for first consumer to be created before binding



kubectl describe pv local-pv
Name:            local-pv
Labels:          <none>
Annotations:     pv.kubernetes.io/bound-by-controller: yes
Finalizers:      [kubernetes.io/pv-protection]
StorageClass:    local-storage
Status:          Bound
Claim:           default/local-claim
Reclaim Policy:  Retain
Access Modes:    RWX
VolumeMode:      Filesystem
Capacity:        10Gi
Node Affinity:   <none>
Message:
Source:
    Type:          HostPath (bare host directory volume)
    Path:          /C/k8s/pv/logs
    HostPathType:
Events:            <none>


kubectl get storageclass local-storage
NAME                      PROVISIONER                    RECLAIMPOLICY   VOLUMEBINDINGMODE      ALLOWVOLUMEEXPANSION   AGE
local-storage   kubernetes.io/no-provisioner   Delete          WaitForFirstConsumer   false                  19m

What piece am I missing? It appears that the local storage class is not bound to a volume claim and tomcat application.

Mike Rother
  • 591
  • 4
  • 16
  • 1
    Does this answer your question? [Setup with Kubernetes hostPath but file doesn't show up in container](https://stackoverflow.com/questions/46032527/setup-with-kubernetes-hostpath-but-file-doesnt-show-up-in-container) – Jonas May 10 '21 at 20:00

0 Answers0