Lab 4.2 - Setup Persistent Storage

1. Clone external storage repository

git clone https://github.com/kubernetes-incubator/external-storage.git kubernetes-incubator

2. Create namespaces for NFS Storage provisioner

oc create namespace openshift-nfs-storage

3. Add monitoring label to namespace

oc label namespace openshift-nfs-storage "openshift.io/cluster-monitoring=true"

4. Configure deployment and RBAC for NFS

# Switch project
oc project openshift-nfs-storage

5. Change namespace on deployment and rbac YAML file

cd /root/kubernetes-incubator/nfs-client/

NAMESPACE=`oc project -q`
sed -i'' "s/namespace:.*/namespace: $NAMESPACE/g" ./deploy/rbac.yaml 
sed -i'' "s/namespace:.*/namespace: $NAMESPACE/g" ./deploy/deployment.yaml

6. Create RBAC

oc create -f deploy/rbac.yaml
oc adm policy add-scc-to-user hostmount-anyuid system:serviceaccount:$NAMESPACE:nfs-client-provisioner

7. Configure deployment

mv deploy/deployment.yaml deploy/deployment.yaml.bak
vim /root/kubernetes-incubator/nfs-client/deploy/deployment.yaml
...
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nfs-client-provisioner
  labels:
    app: nfs-client-provisioner
  # replace with namespace where provisioner is deployed
  namespace: openshift-nfs-storage
spec:
  replicas: 1
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app: nfs-client-provisioner
  template:
    metadata:
      labels:
        app: nfs-client-provisioner
    spec:
      serviceAccountName: nfs-client-provisioner
      containers:
        - name: nfs-client-provisioner
          image: quay.io/external_storage/nfs-client-provisioner:latest
          volumeMounts:
            - name: nfs-client-root
              mountPath: /persistentvolumes
          env:
            - name: PROVISIONER_NAME
              value: storage.io/nfs
            - name: NFS_SERVER
              value: 10.6X.6X.3
            - name: NFS_PATH
              value: /mnt/nfs-server
      volumes:
        - name: nfs-client-root
          nfs:
            server: 10.6X.6X.3
            path: /mnt/nfs-server
...

8. Configure StorageClass

vim /root/kubernetes-incubator/nfs-client/deploy/class.yaml
...
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: managed-nfs-storage
provisioner: storage.io/nfs # or choose another name, must match deployment's env PROVISIONER_NAME'
parameters:
  archiveOnDelete: "false"
...

9. Deploy Deployment and StorageClass

oc create -f deploy/class.yaml 
oc create -f deploy/deployment.yaml

10. Verify the deployment

oc get pods -n openshift-nfs-storage

11. Testing StorageClass

oc create -f deploy/test-claim.yaml -f deploy/test-pod.yaml
oc get pv
oc get pvc
ls /mnt/nfs-server/openshift-nfs-storage-test-claim-pvc-c648a22f-27ba-49f7-b77c-1319a56dbaad/
# SUCCESS

oc delete -f deploy/test-pod.yaml -f deploy/test-claim.yaml

cat > deploy/pvc.yaml << EOF
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: test-claim-pvc
spec:
  storageClassName: managed-nfs-storage
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 100Mi
EOF
oc create -f deploy/pvc.yaml
oc get pv
oc get pvc
oc delete -f deploy/pvc.yaml

12. Set default StorageClass

oc patch storageclass managed-nfs-storage -p '{"metadata": {"annotations": {"storageclass.kubernetes.io/is-default-class": "true"}}}'

Daftar Materi