1. 程式人生 > >k8s-16-k8s基礎儲存

k8s-16-k8s基礎儲存

1.emptyDir

  pod刪除的時候,volume也就不存在了,生命週期和pod同樣

apiVersion: v1
kind: Pod
metadata:
  name: redis-pod
spec:
  containers:
  - image: redis
    name: redis
    volumeMounts:
    - mountPath: /cache
      name: cache-volume
  volumes:
    - name: cache-volume
      emptyDir: {}

2.hostpath

  宿主機上面的目錄,一旦宿主機宕機檔案就不存在,不是分散式的

apiVersion: v1
kind: Pod
metadata:
  name: test-host-pd
spec:
  containers:
  - image: nginx
    name: test-container
    volumeMounts:
    - mountPath: /tmp-test
      name: test-volume
  volumes:
  - name: test-volume
    hostPath:
      path: /opt/data/
      type: Directory

3.nfs分散式的但是 nfs本身為單電

192.168.56.12 部署了nfsserver端   所有node節點需要安裝 nfs-utils
[[email protected] nginx]# cat /etc/exports
/opt/nginx  192.168.56.0/24(rw,no_root_squash)
[[email protected] nginx]# 
[[email protected] nginx]# cat /opt/nginx/index.html 
nginx-index
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  replicas: 2
  template:
    metadata:
      labels:
        app: nginx-nfs
    spec:
      containers:
      - name: nginx-nfs
        image: nginx
        volumeMounts:
        - name: nginxdata
          mountPath: /usr/share/nginx/html
        ports:
        - containerPort: 80
      volumes:
      - name: nginxdata
        nfs:
          server: 192.168.56.12
          path: /opt/nginx


kubectl create -f nginx.yaml
kubectl   expose  deployment   nginx-deployment    --port=90 --type=NodePort  --target-port=80   --name=nginx-service-nfs
kubectl get svc

1.png

2.png

4.glusterfs

5.

6.