k8s_basic_storage

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
k8s_basic_storage [2020/05/25 12:13] – [Dynamic Provisioning] andonovjk8s_basic_storage [2020/05/25 12:49] (current) – [Dynamic Provisioning] andonovj
Line 138: Line 138:
  
 <Code:bash|Pod Specs> <Code:bash|Pod Specs>
 +apiVersion: v1
 kind: Pod kind: Pod
 metadata: metadata:
Line 241: Line 242:
  
 =====Dynamic Provisioning===== =====Dynamic Provisioning=====
-Let's configure Dynamic storage.+Let's configure Dynamic storage. The idea here is that, we (as administrators) care only of the PVC, NOT the PV. So we create the PVC and the provisioner creates teh PV himself. 
 Now, for Dynamic provisioning with NFS I had to re-configure the cluster. In a nutshell make sure that teh API IP which you give when you initiate the cluster has the same subnet of the pod network.  Now, for Dynamic provisioning with NFS I had to re-configure the cluster. In a nutshell make sure that teh API IP which you give when you initiate the cluster has the same subnet of the pod network. 
  
Line 281: Line 283:
   * Claim   * Claim
  
-====Create the Components==== +====Create the Deployment,Service and Service Account====
- +
-===Create Deployment===+
 You can see the deployment,service and service account' YML below: You can see the deployment,service and service account' YML below:
  
Line 498: Line 498:
 </Code> </Code>
  
-===Create Claim===+====Create Storage Claim====
 With Dynamic provisioning, we DON'T Create the Volume, we create ONLY the claim, the volume is created automatically by the provision, that is the MAIN difference With Dynamic provisioning, we DON'T Create the Volume, we create ONLY the claim, the volume is created automatically by the provision, that is the MAIN difference
  
Line 515: Line 515:
     requests:     requests:
       storage: 10Mi       storage: 10Mi
 +ubuntu@k8s-master:~/
 +</Code>
 +
 +====Verify====
 +We can verify the configuration as follows:
 +
 +
 +<Code:bash|Create Claim>
 ubuntu@k8s-master:~/external-storage/nfs/deploy/kubernetes$ kubectl get pv,pvc ubuntu@k8s-master:~/external-storage/nfs/deploy/kubernetes$ kubectl get pv,pvc
 NAME                                                        CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM         STORAGECLASS   REASON   AGE NAME                                                        CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM         STORAGECLASS   REASON   AGE
Line 542: Line 550:
 </Code> </Code>
  
 +====Create a Pod with Dynamic Provisioning====
 +We can of course create a pod which will be using the NFS, let's create NGINX pod for example:
 +
 +<Code:bash|Create NGINX Pod>
 +apiVersion: apps/v1
 +kind: Deployment
 +metadata:
 +  labels:
 +    app: nginx
 +  name: nfs-nginx
 +spec:
 +  replicas: 1
 +  selector:
 +    matchLabels:
 +      app: nginx
 +  template:
 +    metadata:
 +      labels:
 +        app: nginx
 +    spec:
 +      volumes:
 +      - name: nfs #
 +        persistentVolumeClaim:
 +          claimName: nfs  # same name of pvc that was created
 +      containers:
 +      - image: nginx
 +        name: nginx
 +        volumeMounts:
 +        - name: nfs # name of volume should match claimName volume
 +          mountPath: mydata2 # mount inside of contianer
 +ubuntu@k8s-master:~/external-storage/nfs/deploy/kubernetes$ kubectl create -f nginx.yml
 +deployment.apps/nfs-nginx created
 +ubuntu@k8s-master:~/external-storage/nfs/deploy/kubernetes$ kubectl get pods -o wide
 +NAME                              READY   STATUS    RESTARTS   AGE     IP              NODE     NOMINATED NODE   READINESS GATES
 +nfs-nginx-6b4db6f57-4mczr         1/    Running            2m51s   192.168.247.2   node-2   <none>           <none>
 +nfs-provisioner-7795cf6f4-d7m2l   1/    Running            67m     192.168.247.1   node-2   <none>           <none>
 +ubuntu@k8s-master:~/external-storage/nfs/deploy/kubernetes$
 +</Code>
 +
 +Even an ubuntu pod:
 +<Code:bash|ubuntu pod>
 +ubuntu@k8s-master:~$ cat pod.yml
 +apiVersion: v1
 +kind: Pod
 +metadata:
 +  name: first-pod
 +spec:
 +  volumes:
 +    - name: fast10m
 +      persistentVolumeClaim:
 +        claimName: nfs
 +  containers:
 +    - name: ctr1
 +      image: ubuntu:latest
 +      command:
 +      - /bin/bash
 +      - "-c"
 +      - "sleep 60m"
 +      volumeMounts:
 +      - mountPath: "/data"
 +        name: fast10m
 +ubuntu@k8s-master:~$ kubectl get pods -o wide
 +NAME                              READY   STATUS    RESTARTS   AGE     IP               NODE     NOMINATED NODE   READINESS GATES
 +first-pod                         1/    Running            24s     192.168.84.131   node-1   <none>           <none>
 +nfs-nginx-6b4db6f57-4mczr         1/    Running            4m16s   192.168.247.2    node-2   <none>           <none>
 +nfs-provisioner-7795cf6f4-d7m2l   1/    Running            69m     192.168.247.1    node-2   <none>           <none>
 +ubuntu@k8s-master:~$
 +</Code>
 +
 +Eurika, finally we are done with both types of privisioning
  • k8s_basic_storage.1590408793.txt.gz
  • Last modified: 2020/05/25 12:13
  • by andonovj