Skip to content

Instantly share code, notes, and snippets.

@BruceZu
Created January 9, 2017 04:34
Show Gist options
  • Select an option

  • Save BruceZu/35ef618baaa068e4f67b32fc9b65509e to your computer and use it in GitHub Desktop.

Select an option

Save BruceZu/35ef618baaa068e4f67b32fc9b65509e to your computer and use it in GitHub Desktop.
persistent-volumes of k8s kubernetes
http://kubernetes.io/docs/user-guide/persistent-volumes/walkthrough/
@BruceZu
Copy link
Author

BruceZu commented Jan 11, 2017

[root@k8s-08 volumes-ci-cd]# pwd
/volumes-ci-cd
[root@k8s-08 volumes-ci-cd]# chmod -R 777 bugzilla/

[root@k8s-09 ~]# kubectl label nodes  k8s-08 pesistent=bugzilla
[root@k8s-09 ~]# kubectl get nodes --show-labels
NAME                   STATUS    AGE       LABELS
k8s-04.huaweilab.com   Ready     61d       beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/hostname=k8s-04.huaweilab.com
k8s-05.huaweilab.com   Ready     61d       beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/hostname=k8s-05.huaweilab.com
k8s-06.huaweilab.com   Ready     61d       beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/hostname=k8s-06.huaweilab.com
k8s-07.huaweilab.com   Ready     61d       beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/hostname=k8s-07.huaweilab.com
k8s-08.huaweilab.com   Ready     61d       beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/hostname=k8s-08.huaweilab.com,pesistent=bugzilla
k8s-09.huaweilab.com   Ready     61d       beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubeadm.alpha.kubernetes.io/role=master,kubernetes.io/hostname=k8s-09.huaweilab.com
[root@k8s-09 ~]#

then prepare yaml file

[root@k8s-09 ~]# cat bugzilla-host-volume-on-08.yaml
apiVersion: v1
kind: Pod
metadata:
  name: bugzilla.withpv
  labels:
    name: bugzilla.withpv
spec:
  containers:
  - name: bugzilla
    image: dklawren/docker-bugzilla
    ports:
    - containerPort: 80
    - containerPort: 22
    - containerPort: 5900
    securityContext:
      privileged: true
    volumeMounts:
    - mountPath: /home/bugzilla
      name: pv-bugzilla
    - mountPath: /var/lib/mysql
      name: pv-mysql
  nodeSelector:
    pesistent: bugzilla
  volumes:
  - name: pv-bugzilla
    hostPath:
      # directory location on host
      path: /volumes-ci-cd/bugzilla/bugzilla
  - name: pv-mysql
    hostPath:
      path: /volumes-ci-cd/bugzilla/mysql

Test
1 create a test.txt in container and check the content from node
2 delete pod and re deploy it, it is still on the specified node and the status is still there
3 compare with the one without persistent storage pod:
there is not data in the mounted path
http://10.145.101.91:30146/ work
http://10.145.101.91:30146/bugzilla/ does not work
[root@k8s-09 ~]# kubectl expose pod bugzilla.withpv --type=NodePort --name bugzilla-withpv
service "bugzilla-withpv" exposed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment