Welcome!

Using Portworx Shared Volumes

Difficulty:Intermediate

Estimated Time:10 minutes

Portworx is a software defined persistent storage solution designed and purpose built for applications deployed as containers, via container orchestrators such as Kubernetes, Marathon and Swarm. It is a clustered block storage solution and provides a Cloud-Native layer from which containerized stateful applications programmatically consume block, file and object storage services directly through the scheduler.

In this tutorial, you will learn how to deploy multiple replicas of Nginx on Kubernetes and use Portworx Shared Volumes:

Use a Portworx Storage Class to create a shared volume PVC with 3 replicas of the data

Use a simple YAML file to deploy Nginx using this PVC

See how the shared volume allows 3 pods to use the volume at the same time and read/write data to the same file

Shared Volumes Overview

To learn more about how shared volumes can be useful check out our docs page.

This scenario assumes you have already covered the following scenarios:

Steps

Using Portworx Shared Volumes

Wait for Kubernetes & Portworx to be ready

Step: Wait for Kubernetes to be ready

Click the below section which waits for all Kubernetes nodes to be ready.

watch kubectl get nodes

When all 4 nodes show status Running then hit clear to ctrl-c and clear the screen.

Step: Wait for Portworx to be ready

Watch the Portworx pods and wait for them to be ready on all the nodes. This can take a few minutes since it involves pulling multiple docker images. You will see 'No resources found' until all images are pulled.

watch kubectl get pods -n kube-system -l name=portworx -o wide

When all the pods show STATUS Running and READY 1/1 then hit clear to ctrl-c and clear the screen.

Now that we have the Portworx cluster up, let's proceed to the next step !

Create shared volume

In this step, we will create a Portworx volume (PVC) for nginx.

Step: Create StorageClass

Take a look at the StorageClass definition for Portworxcat px-shared-sc.yaml

The parameters are declarative policies for your storage volume. See here for a full list of supported parameters. In our case the key parameter is shared=true.

Create the storage class using:

kubectl create -f px-shared-sc.yaml

Step: Create PersistentVolumeClaim

Take a look at the Persistent Volume Claimcat px-shared-pvc.yaml

Here we're pointing at the storage class defined above and giving our volume a maximum size (Portworx thinly provisions volumes so that space will not be reserved up-front).

Create the PersistentVolumeClaim using:

kubectl create -f px-shared-pvc.yaml

Now that we have the volumes created, let's deploy a few nginx instances and see how the shared volumes work!

Deploy nginx

In this step, we will deploy the nginx application using the PersistentVolumeClaim created before.

Step deploy 3 instances of nginx

Take a look at the yaml:
cat deploy-webapps.yaml

Observe the volumeMounts and volumes sections where we mount the PVC.

Now use kubectl to deploy nginx.

kubectl create -f deploy-webapps.yaml

Step: Verify nginx pods are ready

Run the below command and wait till all three nginx pods are in ready state.

watch kubectl get pods -l group=webapp -o wide

When all three pods are in Running state then then hit clear to ctrl-c and clear the screen. Be patient, if it's staying in Pending state for a while it's because it has to fetch the docker image on each node.

Inspect the volume

In this step, we will use pxctl to inspect the volume

Step: Inspect the Portworx volume

Portworx ships with a pxctl command line that can be used to manage Portworx.

Status indicates the volume is attached and shows the node on which it is attached. For shared volumes, this is the transaction coordinator node which all other nodes will go through to write the data.

HA shows the number of configured replicas for this volume (shared volumes can be replicated of course, you can try it by modifying the storage class in step 2)

Now that we have our shared volumes created and mounted into all three nginx containers, let's proceed to write some data into the html folder of nginx and see how it gets read by all three containers.

Validate

In this step, we will check the state of our sample postgres database.

Debugging Scenarios

Help

Katacoda offerings an Interactive Learning Environment for Developers. This course uses a command line and a pre-configured sandboxed environment for you to use. Below are useful commands when working with the environment.

cd <directory>

Change directory

ls

List directory

echo 'contents' > <file>

Write contents to a file

cat <file>

Output contents of file

Vim

In the case of certain exercises you will be required to edit files or text. The best approach is with Vim. Vim has two different modes, one for entering commands (Command Mode) and the other for entering text (Insert Mode). You need to switch between these two modes based on what you want to do. The basic commands are: