kubernetes存储

kubernetes4种存储:

kubernetes-configMap:存储配置文件

kubernetes-secret:加密信息(密码,用户名密码信息)

kubernetes-volume:给pod提供共享存储服务

kubernetes-persistent volume:PV,PVC持久卷

[root@k8s-master01 ~]# cd /usr/local/
aegis/        etc/          install-k8s/  libexec/      src/          
bin/          games/        lib/          sbin/         
cloudmonitor/ include/      lib64/        share/        
[root@k8s-master01 ~]# cd /usr/local/install-k8s/
[root@k8s-master01 install-k8s]# ll
total 8
drwxr-xr-x 2 root root 4096 Jul 10 00:50 core
drwxr-xr-x 4 root root 4096 Jul 30 13:39 plugin
[root@k8s-master01 install-k8s]# mkdir volume
[root@k8s-master01 install-k8s]# cd volume/
[root@k8s-master01 volume]# ll
total 0
[root@k8s-master01 volume]# vim em.yaml
[root@k8s-master01 volume]# kubectl apply -f em.yaml 
pod/test-pd created
[root@k8s-master01 volume]# kubectl get pod
NAME      READY   STATUS    RESTARTS   AGE
test-pd   1/1     Running   0          14s
[root@k8s-master01 volume]# 
[root@k8s-master01 volume]# kubectl exec test-pd -it -- /bin/sh
/ # cd /cache/
/cache # ll
/bin/sh: ll: not found
/cache # ls
/cache # [root@k8s-master01 volume]# vim em.yaml 
[root@k8s-master01 volume]# kubectl exec test-pd(pod名称) -c test-container(容器名称) -it -- /bin/sh
apiVersion: v1
kind: Pod
metadata:
  name: test-pd
spec:
  containers:
  - image: hub.msjfkg.com/library/myapp:v1
    name: test-container
    volumeMounts:
    - mountPath: /cache #不同的目录共享一个volume
      name: cache-volume
  - name: liveness-exec-container
    image: busybox
    imagePullPolicy: IfNotPresent
    command: ["/bin/sh","-c","sleep 6000s"]
    volumeMounts:
    - mountPath: /test
      name: cache-volume
  volumes:
  - name: cache-volume
    emptyDir: {}

同一个pod下进入不同容器的方式:
[root@k8s-master01 volume]# kubectl exec test-pd -c test-container -it -- /bin/sh

 hostPath 

除了所需的path属性之外,用户还可以为hostPath卷指定type

apiVersion: v1
kind: Pod
metadata:
  name: test-pd
spec:
  containers:
  - image: k8s.gcr.io/test-webserver
    name: test-container
    volumeMounts:
    - mountPath: /test-pd
      name: test-volume
  volumes:
  - name: test-volume
    hostPath:
      # directory location on host
      path: /data
      # this field is optional
      type: Directory

容器中的/test-pd目录共享到本机的/data目录下

  

原文地址:https://www.cnblogs.com/tian880820/p/13404861.html