Home > Archives > Volumes示例

Volumes示例

Publish:

emptyDir

---
apiVersion: v1
kind: Pod
metadata:
  name: test-pd
spec:
  containers:
  - image: k8s.gcr.io/test-webserver
    name: test-container
    volumeMounts:
    - mountPath: /cache
      name: cache-volume
  volumes:
  - name: cache-volume
    emptyDir: {}
	
hostPath

---
# hostpath-example.yaml 
apiVersion: v1
kind: Pod
metadata:
  name: apiserver
spec:
  containers:
  - name: apiserver
    image: zxcvbnius/docker-demo
    volumeMounts:
    - mountPath: /tmp
      name: tmp-volume
    imagePullPolicy: Always
  volumes:
  - name: tmp-volume
    hostPath:
      path: /tmp
      type: Directory

kubectl create -f hostpath-example.yaml
kubectl exec -it apiserver sh
ls /tmp
echo "Hello World" > /tmp/test.txt
cat /tmp/test.txt
exit

NFS(Network FileSystem)

---
# nfs-example.yaml
apiVersion: v1
kind: Pod
metadata:
  name: apiserver
spec:
  containers:
  - name: apiserver
    image: zxcvbnius/docker-demo
    ports:
      - name: api-port
        containerPort: 3000
    volumeMounts:
      - name: nfs-volumes
        mountPath: /tmp
  volumes:
  - name: nfs-volumes
    nfs:
     server: {YOUR_NFS_SERVER_URL}
     path: /


参考

声明: 本文采用 BY-NC-SA 授权。转载请注明转自: Ding Bao Guo