In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
Volume is a shared directory accessed by multiple containers in kubernetes Pod
Kubernetes provides many volume types, including: emptyDir, hostPath, NFS, GlusterFS, configMap, Cephfs
1 、 emptyDir
Vloume of emptyDir type is created when Pod is assigned to node, and kubernetes automatically allocates a directory on node, so there is no need to specify the corresponding directory file on host node. The directory initialization content is empty. When Pod is removed from node, the data in emptyDir will be permanently deleted.
1. Edit the emptyDir.yaml file
ApiVersion: extensions/v1beta1kind: Deploymentmetadata: name: web-demo-emptyspec: replicas: 2 selector: matchLabels: app: app-demo-empty template: metadata: labels: app: app-demo-empty spec: containers:-name: tomcat-demo image: tomcat imagePullPolicy: IfNotPresent ports:-containerPort: 8080 volumeMounts: # add / mydata-data directory Mount to a shared repository-mountPath: / mydata-data name: datavol-name: nginx-demo image: nginx imagePullPolicy: IfNotPresent ports:-containerPort: 80 volumeMounts: # Mount the / mydata-data directory to the shared repository-mountPath: / mydata-data name: datavol # emptyDir is a shared repository Library (central warehouse) volumes:-name: datavol emptyDir: {}
two。 Execute kubectl create
$kubectl create-f emptyDir.yamldeployment.extensions/web-demo-empty created
3. First go to the tomcat-demo container to create a file
$kubectl exec-it web-demo-empty-9b5644c45-7bpn5-c tomcat-demo bash$ touch / mydata-data/data.txt$ ls / mydata-data/data.txt
4. Check whether the data.txt file exists in the nginx-demo container.
$kubectl exec-it web-demo-empty-9b5644c45-7bpn5-c nginx-demo bash$ ls / mydata-data/data.txt
It has been proved that emptyDir is a shared empty directory, which can be shared among multiple containers in Pod.
2 、 hostPath
HostPath type vloume is a directory or file mounted to the host by Pod, so that the container can use the host's file system for storage. However, in kubernetes, Pod is based on the schedule component to dynamically schedule to different node nodes. When a Pod is launched on the current node node and stores files locally through hostPath, the files stored on the previous node cannot be used the next time it is started on another node.
1. Edit the hostPath.yaml file
ApiVersion: extensions/v1beta1kind: Deploymentmetadata: name: web-demo-hostpathspec: replicas: 2 selector: matchLabels: app: app-demo-hostpath template: metadata: labels: app: app-demo-hostpath spec: containers: containers:-name: nginx-demo image: nginx imagePullPolicy: IfNotPresent ports:-containerPort: 80 volumeMounts:-mountPath: / mydata-data name: datavol volumes:-name: datavol hostPath: path: "/ data"
two。 Execute kubectl create
$kubectl create-f hostPath.yamldeployment.extensions/web-demo-hostpath created
3. You need to create a / data directory on each node node and create a test file
$mkdir / data $touch / data/test.txt
4. Go to the container to see if / mydata-data is mounted on the host machine.
$kubectl exec-it web-demo-hostpath-7866c644c4-7f8fk bash$ ls / mydata-data/test.txt
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.