Creating a local volume on the node

The pod definition file below creates a volume at location /data on the node and mounts it to the location /opt in the container. The volume is created at the pod level and it mounted at the container level.

apiVersion: v1
kind: Pod
metadata:
  labels:
    name: frontend
spec:
  containers:
	  - name: httpd
	    image: httpd:2.4-alpine
			volumeMounts:
				- name: data-volume
					mountPath: /opt

	volumes:
		- name: data-volume
			hostPath: 
				path: /data
				type: Directory

Untitled

Creating a shared remote volume on EBS

The pod definition file below creates a volume on EBS and mounts it to the location /opt in the container. Even if the pods are running on multiple nodes, they will still read the same data.

apiVersion: v1
kind: Pod
metadata:
  labels:
    name: frontend
spec:
  containers:
	  - name: httpd
	    image: httpd:2.4-alpine
			volumeMounts:
				- name: data-volume
					mountPath: /opt

	volumes:
		- name: data-volume
			awsElasticBlockStore: 
				volumeId: <volume-id>
				fsType: ext4

<aside> ⚠️ Configuring volumes at the pod level (in every pod definition file) is not the right way. If we want to switch all the volumes from local to remote, we need to update every pod definition file.

</aside>

Persistent Volumes

Untitled