简体   繁体   中英

Converting from docker-compose to Kubernetes - how to deal with volumes on local

I'm try to get my local development environment converted from docker-compose to a flavour of lightweight Kubernetes, since our production environments are all Kubernetes (like). With the help of Kompose I could convert my settings. The part however I struggle with is the conversion of Docker volumes to a local developer machine Volume and Volume claim. Most examples I found cover drivers for S3 or NFS, which isn't what my development laptop offers.

So when I have in my docker-compose.yml a setting like this, what's the local development equivalent in k8s?

version: "3.6"
services:
  my_test:
    image: "myregistry.com/my_test"
    container_name: "demo"
    hostname: "demo.acme.local"
    stop_grace_period: 120s
    cap_add:
      - SYS_PTRACE
    ports:
      - 80:80
    volumes:
      - my_vol:/local/my_app
volumes:
  my_vol:
    name: "/local/containers/my_app"
    external: false

I'm "only" looking for the volume part. The rest seems clear.
Help is appreciated

Yes you can use the host path or you can use the emptydir that's on you

Probably hostpath would be a better option.

If you are planning to use the minikube you can also check out the PV and PVC option which is mostly for the persistence storage in Kubernetes.

Hostpath : https://kubernetes.io/docs/concepts/storage/volumes/#hostpath-configuration-example

emptydir : https://kubernetes.io/docs/concepts/storage/volumes/#emptydir

Both solutions ( hostpath and emptydir ) you found looks good.

Here you have documentations to both ones:


A hostPath volume mounts a file or directory from the host node's filesystem into your Pod.

To the required path property, you can also specify a type for a hostPath volume.

NOTE : HostPath volumes present many security risks, and it is a best practice to avoid the use of HostPaths when possible. When a HostPath volume must be used, it should be scoped to only the required file or directory, and mounted as ReadOnly .


An emptyDir volume is first created when a Pod is assigned to a node, and exists as long as that Pod is running on that node.

EmptyDir volume is initially empty. All containers in the pod have permissions in the emptyDir volume to read and write the same files, despite possibility of diffrent localisations of that volume (it can be mounted at the same or different paths in each container).

In case the Pod is removed from a node for any reason, the data in the emptyDir is deleted permanently .

Depending on your environment, emptyDir volumes are stored on whatever medium that backs the node such as disk or SSD, or network storage.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM