需求:容器产生的文件不允许有任何丢失

hostPath特性:pod在删除后,宿主机上的文件,不会丢失

 

yaml文件:

[k8s@k8s-m1 yaml]$ cat centos-test.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: centos-deployment-test
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: centos-deployment-label
    spec:
      nodeSelector:
        hostname: node_phy
      containers:
      - name: centos1
        image: centos:latest
        ports:
        - containerPort: 80
        imagePullPolicy: Never
        command: ["/bin/sleep","999"]
        volumeMounts:
        - mountPath: /data/logs/
          name: logdir
          subPath: centos1
      - name: centos2
        image: centos:latest
        ports:
        - containerPort: 80
        imagePullPolicy: Never
        command: ["/bin/sleep","999"]
        volumeMounts:
        - mountPath: /data/logs/
          name: logdir
          subPath: centos2
      - name: centos3
        image: centos:latest
        ports:
        - containerPort: 80
        imagePullPolicy: Never
        command: ["/bin/sleep","999"]
        volumeMounts:
        - mountPath: /data/logs/
          name: logdir
          subPath: centos3
      volumes:
      - name: logdir
        #emptyDir: {}
        hostPath:
          path: /data/logs
          type: DirectoryOrCreate

 

宿主机的目录如下

[root@tjwq01-video-live064014069 ~]# cat /data/logs/centos2/centos2
centos2
2
[root@tjwq01-video-live064014069 ~]# cat /data/logs/centos2/centos2
centos2
2
[root@tjwq01-video-live064014069 ~]# ls -lh /data/logs/*
/data/logs/centos1:
total 0
-rw-r--r-- 1 root root 0 Apr 11 17:16 centos1

/data/logs/centos2:
total 8.0K
-rw-r--r-- 1 root root   10 Apr 11 17:20 centos2

/data/logs/centos3:
total 0

 

转载于:https://www.cnblogs.com/aast/p/10691079.html

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐