Gestione dei volumi persistenti in Tanzu Kubernetes Grid (EN)

How to deploy an application in Tanzu Kubernetes Grid with persistent volumes

Last updated 10th November 2022

Objective

This guide documents how to manage persistent volumes on a Tanzu Kubernetes Grid cluster.

OVHcloud provides services for which you are responsible, with regard to their configuration and management. It is therefore your responsibility to ensure that they work properly.

This guide is designed to assist you as much as possible with common tasks. However, we recommend contacting a specialist provider if you experience any difficulties or doubts when it comes to managing, using or setting up a service on a server.

Requirements

Introduction

Persistent volumes are used to store data permanently on a Kubernetes cluster. This mechanism is based on Storage Classes. There are various Storage Classes. Read the Kubernetes Storage Classes guide for more information.

When deploying a WorkLoad cluster, a Storage Class CSI provisioner is created and points to the Datastore folder that contains the virtual machines in the WorkLoad cluster.

From your VMware cluster, go to the inventory. Select the storage icon to the left, and go to the datastore where your WorkLoad cluster was deployed. Go to the Files tab and click the fcd folder.

The folder is empty because the WorkLoad cluster does not yet use persistent volumes.

01 Display FCD folder

You can create additional Storage Classes for each WorkLoad cluster.

Instructions

We will connect to a WorkLoad cluster from the console of the Bootstrap virtual machine. You can use the Tanzu Management Cluster Grid administration guide to create and manage a workload cluster.

From the Bootstrap virtual machine console, run this command to view the contexts that can be used on this cluster:

# Display all the contexts of your TANZU KUBERNETES GRID cluster
kubectl config get-contexts

Run this command to use the WorkLoad cluster:

# Connect to WorkLoad cluster
kubectl config use-context tkgm-workload-cluster-admin@tkgm-workload-cluster

Displaying Existing Storage Classes

For information about the Storage Classes in a WorkLoad cluster, run these commands:

# Display Storage Classes
kubectl get storageclass
# Storage Class description
kubectl describe storageclass nomclasse

Creating a storage class on another datastore

On our VMware cluster, we have two datastores connected to NFS servers. One of the datastores contains the virtual machines in the WorkLoad cluster, as well as the fcd folder used by the Storage Class in the Workload cluster.

We will create a new Storage Class on the second datastore.

Go back to your VMware cluster in storage management, select the second datastore, and click Summary in the tab on the left.

Copy the URL below "Type: NFS 3".

02 Select URL01

Go to the console of the Bootstrap virtual machine, edit a new file named secondstorageclass.yaml with this content:

kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: secondstorageclass
  annotations:
    storageclass.kubernetes.io/is-default-class: "true"
provisioner: csi.vsphere.vmware.com
parameters:
  datastoreurl: "ds:///vmfs/volumes/xxxxxxxxxxxxxxxxx/"

Edit the file by replacing ds:///vmfs/volumes/xxxxxxxxxxxxxxxxx/ with the URL you just copied.

Next, run this command:

# Creating storageclass from yaml file
kubectl apply -f secondstorageclass.yaml
# Display storageclasses
kubectl get storageclass

We are now seeing two Storage Classes:

NAME                           PROVISIONER              RECLAIMPOLICY   VOLUMEBINDINGMODE   ALLOWVOLUMEEXPANSION   AGE
default (default)              csi.vsphere.vmware.com   Delete          Immediate           true                   3d18h
secondstorageclass (default)   csi.vsphere.vmware.com   Delete          Immediate           false                  12s
tanzu@bootstrap:~$

Creating a persistent volume in the default Storage class

Create a file named default-pvc-storage.yaml with this content:

kind: persistantVolumeClaim
apiVersion: v1
metadata:
  name: default-pvc-storage
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: "default"
  resources:
    requests:
      storage: 2Gi

The persistent storage name is next to name, storageClassName contains the name of the Storage Class that is used for this volume.

Run this command to create the persistent volume:

# Create a namespace that will be used for my persistent volume.
kubectl create namespace myspace
# Applying the configuration file to the created namespace.
kubectl apply -f default-pvc-storage.yaml -n myspace
# Display persistent volumes of created namespace
kubectl get pv,pvc -n myspace

Go back to the inventory in your vCenter interface, click on the DataCenter icon on the left, then go to the Monitor tab on the right, and click on Container Volumes to see the persistent volumes.

The persistent volume that has been created is displayed, and to the right you can see the name of the datastore on which it is stored.

03 Display PV in vCenter 01

Click the notebook icon to the left of the volume to view the details.

03 Display PV in vCenter 02

The information about this persistent storage is displayed, and corresponds to what was created using Kubernetes commands.

03 Display PV in vCenter 03

Go to the Datastore that is used by default, right-click the Files tab and scroll through the folders in the Datastore to the fcd folder.

You see that the folder contains two files, a vmdk file that contains the persistent volume data and an associated temporary file.

03 Display PV in vCenter 04

Creating a persistent volume on the second Storage Class

Return to the Bootstrap virtual machine and use the command line.

Create a file named second-storage-pvc.yaml:

kind: persistantVolumeClaim
apiVersion: v1
metadata:
  name: second-storage-pvc
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: "secondstorageclass"
  resources:
    requests:
      storage: 2Gi

The file uses the same syntax as the first persistent storage, but with a different name and Storage Class.

Run this command to create the persistent volume in the myspace namespace:

# Applying the configuration file to the created namespace.
kubectl apply -f second-storage-pvc.yaml -n myspace
# Display persistent volumes of created namespace
kubectl get pv,pvc -n myspace

The persistent volume is created on the second Datastore.

Return to the vCenter interface. You will see that you do not have any new files in the fcd folder.

04 Display PV2 in vCenter 01

Right-click the second Datastore, go to the fcd folder for that datastore. You will see that you have two new files, as in the first datastore.

04 Display PV2 in vCenter 02

Go back to the Datacenter at the root of the datacenters, click on the Monitor tab, and choose Container volumes to see the two persistent volumes appear with their locations in the datastores.

04 Display PV2 in vCenter 03

Go further

Introduction to Tanzu Kubernetes Grid at OVHcloud

Installing Tanzu Kubernetes Grid

Managing Tanzu Management Cluster Grid

Introducing VMware Tanzu Kubernetes Grid

VMware Tanzu Kubenetes Grid documentation

Manual installation of the CLI tool for the deployment of Tanzu Kubernetes GRID

Join our community of users on https://community.ovh.com/en/.


Questa documentazione ti è stata utile?

Prima di inviare la valutazione, proponici dei suggerimenti per migliorare la documentazione.

Immagini, contenuti, struttura... Spiegaci perché, così possiamo migliorarla insieme!

Le richieste di assistenza non sono gestite con questo form. Se ti serve supporto, utilizza il form "Crea un ticket" .

Grazie per averci inviato il tuo feedback.


Potrebbero interessarti anche...

OVHcloud Community

Accedi al tuo spazio nella Community Fai domande, cerca informazioni, pubblica contenuti e interagisci con gli altri membri della Community OVHcloud

Discuss with the OVHcloud community

Conformemente alla Direttiva 2006/112/CE e successive modifiche, a partire dal 01/01/2015 i prezzi IVA inclusa possono variare in base al Paese di residenza del cliente
(i prezzi IVA inclusa pubblicati includono di default l'aliquota IVA attualmente in vigore in Italia).