In Azure Kubernetes Service (AKS), a Persistent Volume (PV) is a storage resource in the cluster that can be dynamically provisioned or statically provisioned. The main difference between a PV static and a PV dynamic in AKS is in how they are provisioned.
A PV static is provisioned by an administrator before a pod is created. The administrator creates the PV object and allocates storage capacity from a pre-existing storage resource. The PV object is then used by the pod to access the allocated storage. This approach allows the administrator to manage the storage resources for the cluster and provision the required storage capacity in advance.
On the other hand, a PV dynamic is provisioned on-demand when a pod requests storage. When a pod requests storage, the Kubernetes control plane creates a PV object and allocates storage capacity from a pre-defined storage class. The storage class specifies the type of storage, such as block or file-based storage, and other configuration parameters, such as the storage capacity and the storage location.
The advantage of using a PV dynamic in AKS is that it allows for more flexibility in managing storage resources for the cluster. With dynamic provisioning, you can create and delete PVs on demand, and you can use storage classes to define the type and configuration of storage resources. This approach can help optimize the use of storage resources in the cluster and reduce the management overhead for administrators.
In summary, the main difference between a PV static and a PV dynamic in AKS is that the former is provisioned in advance by an administrator, while the latter is provisioned on-demand when a pod requests storage. Both approaches have their advantages and can be used depending on the requirements of your application and storage management needs.
Example of Static PV Provision:-
Create a PV with name pv-azure-file-sql
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-azure-file-sql
labels:
pv-name: pv-azure-file-sql
spec:
capacity:
storage: 10Gi
accessModes:
- ReadWriteMany
storageClassName: azurefile
azureFile:
secretName: azure-secret
shareName: sql-fileshare
readOnly: false
mountOptions:
- dir_mode=0777
- file_mode=0777
- uid=10001
- gid=10001
persistentVolumeReclaimPolicy: Retain
--- Create a Persistent volume claim
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: my-pvc-sql
namespace: rak
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 1Gi
storageClassName: azurefile
selector:
matchLabels:
pv-name: pv-azure-file-sql
--- Create a deployment which will consume the PVC
apiVersion: apps/v1
kind: Deployment
metadata:
name: mssql-deployment
namespace: rak
spec:
replicas: 1
selector:
matchLabels:
app: mssql
template:
metadata:
labels:
app: mssql
spec:
terminationGracePeriodSeconds: 30
hostname: mssqlinst
securityContext:
fsGroup: 10001
containers:
- name: mssql
image: mcr.microsoft.com/mssql/server:2019-latest
resources:
requests:
memory: "1G"
cpu: "2000m"
limits:
memory: "1G"
cpu: "2000m"
ports:
- containerPort: 1433
env:
- name: MSSQL_PID
value: "Developer"
- name: ACCEPT_EULA
value: "Y"
- name: MSSQL_SA_PASSWORD
valueFrom:
secretKeyRef:
name: mssql
key: MSSQL_SA_PASSWORD
volumeMounts:
- name: mssqldb
mountPath: /var/opt/mssql
volumes:
- name: mssqldb
persistentVolumeClaim:
claimName: my-pvc-sql
--- Create a Service which will
apiVersion: v1
kind: Service
metadata:
name: mssql-deployment
namespace: rak
spec:
selector:
app: mssql
ports:
- protocol: TCP
port: 1433
targetPort: 1433
type: LoadBalancer
---
Example of Dynamic PV Provisioning:-
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: azure-disk-sc
provisioner: kubernetes.io/azure-disk
parameters:
storageaccounttype: Standard_LRS
---
apiVersion: v1
kind: Pod
metadata:
name: my-pod
namespace: rak
spec:
containers:
- name: my-container
image: nginx:latest
volumeMounts:
- name: my-volume
mountPath: /data
volumes:
- name: my-volume
persistentVolumeClaim:
claimName: my-pvc-dynamic
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: my-pvc-dynamic
namespace: rak
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi
storageClassName: azure-disk-sc
No comments:
Post a Comment