Kubernetes section Volume type Introduction and YAML sample--emptydir

Source: Internet
Author: User
Tags tmp file


Kubernetes section Volume type Introduction and Yaml sample--emptydir (Local data volume)


kubernetes volumes


  1. kubernetes persistent volume
  2. Description、volume mount kubernetes
    The Emptydir type of volume is created when the pod is dispatched to a host, kubernetes volume mount and the container within the same pod can read and write to the same file in the Emptydir. Once the pod has left the host, the data in the Emptydir will be permanently deleted. So the current Emptydir type of volume is primarily used as a temporary space, kubernetes persistent volumes example persistent volume kubernetes such as a Web server write log or a temp directory required by the TMP file.
  3. kubernetes persistent volume claim
  4. Standard single-container pod with shared volumes
    #创建yaml文件cat >> emptyDir.yaml << EOFapiVersion: v1kind: Podmetadata:    labels:        name: test-emptypath        role: master    name: test-emptypath    namespace: testspec:    containers:        - name: test-emptypath            image: nginx:1.7.9            volumeMounts:             - name: log-storage                 mountPath: /tmp/    volumes:    - name: log-storage        emptyDir: {}
    #启动emptyDir.yamlkubectl create -f ./emptyDir.yaml
    #查看Pod运行状态kubectl get po -n testNAME                         READY     STATUS    RESTARTS   AGEtest-emptypath               1/1       Running   0          3h##说明:当 Pod 被分配给节点时,首先创建 emptyDir 卷,并且只要该 Pod##在该节点上运行,该卷就会存在。正如卷的名字所述,它最初是空的。
  5. The standard multi-container pod that uses shared volumes,kubernetes volume mounts
    #创建yaml文件
    cat  >> emptyDir2.yaml << EOFapiVersion: v1kind: Podmetadata:    name: datagrand    namespace: testspec:    containers:    - name: test1        image: nginx:1.7.9        volumeMounts:        - name: log-storage            mountPath: /usr/share/nginx/html    - name: test2        image: centos        volumeMounts:        - name: log-storage            mountPath: /html        command: ["/bin/sh","-c"]        args:            - while true;do                    data >> /html/index.html;                    sleep 1;                donevolumes:    - name: log-storage        emptyDir: {}##说明:在这个例子中,我们定义了一个名为HTML的卷。它的类型是emptyDir,##这意味着当一个POD被分配到一个节点时,卷先被创建,并只要Pod在节点上##运行时,这个卷仍存在。正如名字所说,它最初是空的。第一容器运行nginx的##服务器并将共享卷挂载到目录/ usr /share/ nginx /html。第二容器使用centos##的镜像,并将共享卷挂载到目录/HTML。每一秒,第二容器添加当前日期和时##间到index.html文件中,它位于共享卷。当用户发出一个HTTP请求到POD,##nginx的服务器读取该文件并将其传递给响应请求的用户。
    
    
    #查看Pod运行状态kubectl get po -n testNAME                         READY     STATUS    RESTARTS   AGEdatagrand                    2/2       Running   0          22m
    
    
    #进入容器test2kubectl exec -it datagrand -c test2 /bin/bash -n test[[email protected] /]# cd html[[email protected] html]# lsindex.html[[email protected] html]# cat index.html this is a test##emptyDir卷是两个容器(test1和test2)共享的
  6. Reference documents
    Https://www.kubernetes.org.cn/2767.html


Kubernetes section Volume type Introduction and YAML sample--emptydir


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.