k8s-hostpath-device-plugin

command module
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 10, 2023 License: MIT Imports: 3 Imported by: 0

README

k8s-hostpath-device-plugin

This is a very thin device plugin which just exposed a host path to a container.

This can be seen as non limited resources, things like "capabilitites" of a host. However, due to kubernetes/kubernetes#59380, current device plugin(v1beta1) doesn't support unlimited extended resources. Currently a hack would be to set the number of resources advertised by the device plugin to a very high mumber.

Why not using hostPath volume?? The question is natural. But, hostPath volume assumes all the nodes in the cluster have the hostPath. What happened if only part of the nodes serve the host path? Assume user pod's spec declares a host path volume like below:

kind: Pod
spec:
...
  volumes:
  - name: vol
    hostPath:
      path: /mnt/volume

Then, how to make sure that the pod is scheduled to a node which has host path /mnt/volume??

This device plugin solve this by serving the exising hostpath as extended resource like this:

kind: Pod
...
    resources:
      limits:
        # the resource mounts hostPath=/sample to contianerPath=/sample
        hostpath-device.k8s.io/sample: 1

Thus, it can guarantee that the pod will be scheduled to a node which has the host path.

Build

docker build . -t k8s-hostpath-device-plugin

Deploy

First you edit example/config.yaml. Then, you can deploy the device plugin:

kustomize build example/ | kubectl apply -f -

Try with Kind

# create a kind cluster
# - create kind cluster
# - prepare hostpath=/sample
# - install cert-manager
$ make dev-cluster

# deploy
# - k8s-hostpath-device-plugin
# - its webhook
$ make dev-deploy
# create pod requesting 'hostpath-device.k8s.io/sample=1'
$ cat << EOT | kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
  name: test-hostpath-sample
spec:
  restartPolicy: Never
  containers:
  - name: ctr
    image: busybox
    command:
    - sh
    - -c
    - |
      set -ex
      ls -al /sample
      cat /sample/hello
    resources:
      limits:
        # the resource mounts hostPath=/sample to contianerPath=/sample
        hostpath-device.k8s.io/sample: 1
EOT

# you can see pod can access to /sample from a container
$ kubectl logs test-hostpath-sample
+ ls -al /sample
total 12
drwxr-xr-x    2 root     root          4096 Aug 27 16:43 .
drwxr-xr-x    1 root     root          4096 Aug 27 17:00 ..
-rw-r--r--    1 root     root             6 Aug 27 16:43 hello
+ cat /sample/hello
hello
+ exit 0

# cleanup
$ make dev-clean

How to make a release

The release process is fully automated by tagpr. To release, just merge the latest release PR.

License

MIT License. See LICENSE file.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL