DEV Community

Wycliffe A. Onyango
Wycliffe A. Onyango

Posted on

100 Days of DevOps: Day 60

Persistent Volumes in Kubernetes

The following log details the step-by-step deployment of the Kubernetes web application, including the YAML file contents, application commands, and successful verification output.

1. Resource Definitions (YAML Files)

The project required four distinct resources, defined in separate files: pv.yaml, pvc.yaml, pod.yaml, and service.yaml.

pv.yaml (PersistentVolume)

apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv-devops
spec:
  storageClassName: manual
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: /mnt/dba
Enter fullscreen mode Exit fullscreen mode

pvc.yaml (PersistentVolumeClaim)

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: pvc-devops
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
Enter fullscreen mode Exit fullscreen mode

pod.yaml (Pod)

apiVersion: v1
kind: Pod
metadata:
  name: pod-devops
  labels:
    app: web-devops
spec:
  containers:
    - name: container-devops
      image: httpd:latest
      ports:
        - containerPort: 80
      volumeMounts:
        - name: devops-storage
          mountPath: /usr/local/apache2/htdocs
  volumes:
    - name: devops-storage
      persistentVolumeClaim:
        claimName: pvc-devops
Enter fullscreen mode Exit fullscreen mode

service.yaml (Service)

apiVersion: v1
kind: Service
metadata:
  name: web-devops
spec:
  type: NodePort
  selector:
    app: web-devops
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
      nodePort: 30008
Enter fullscreen mode Exit fullscreen mode

2. Deployment Steps and Output

The resources were applied sequentially to ensure the storage components were ready before the application Pod was deployed.

Step Command Output Result
1. Apply PV kubectl apply -f pv.yaml persistentvolume/pv-devops created Success. PV created.
2. Apply PVC kubectl apply -f pvc.yaml persistentvolumeclaim/pvc-devops created Success. PVC created.
3. Apply Service kubectl apply -f service.yaml service/web-devops created Success. Service created, waiting for Pod endpoints.
4. Apply Pod kubectl apply -f pod.yaml pod/pod-devops created Success. Pod created, starting container.

3. Verification Commands and Final State

Verification confirmed that all components are Bound and Running.

PV and PVC Status

This verification confirms the storage claim was successfully bound.

thor@jumphost ~$ kubectl get pv pv-devops
NAME        CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM                   STORAGECLASS   AGE
pv-devops   5Gi        RWO            Retain           Bound    default/pvc-devops      manual         5m29s
thor@jumphost ~$ kubectl get pvc pvc-devops
NAME         STATUS   VOLUME      CAPACITY   ACCESS MODES   STORAGECLASS   AGE
pvc-devops   Bound    pv-devops   5Gi        RWO            manual         5m15s
Enter fullscreen mode Exit fullscreen mode

Pod Status

This verification confirms the Pod is running and ready.

thor@jumphost ~$ kubectl get pods
NAME          READY   STATUS    RESTARTS   AGE
pod-devops    1/1     Running   0          17s
Enter fullscreen mode Exit fullscreen mode

Service Endpoints

This verification confirms the Service has successfully found and connected to the running Pod.

thor@jumphost ~$ kubectl describe service web-devops
Name:                     web-devops
Namespace:                default
...
Selector:                 app=web-devops
Type:                     NodePort
...
Port:                     <unset>  80/TCP
TargetPort:               80/TCP
NodePort:                 <unset>  30008/TCP
Endpoints:                10.244.0.5:80   # <--- CRITICAL: Endpoints are now listed!
Session Affinity:         None
...
Enter fullscreen mode Exit fullscreen mode

The presence of the Endpoints (10.244.0.5:80) confirms the Service is correctly routing traffic to the running Pod. The application is now fully exposed on NodePort 30008.

Top comments (0)