k8s-hostpath-device-plugin

command module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2021 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

release make target tags a commit and push the tag to origin. Release process will run in GitHub Action.

$ RELEASE_TAG=$(git semv patch) # next patch version.  bump major/minor version if necessary
$ make release RELEASE=true RELEASE_TAG=${RELEASE_TAG}

License

MIT License. See LICENSE file.

Documentation

Overview

Copyright © 2021 NAME HERE <EMAIL ADDRESS>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Directories

Path Synopsis
pkg

Jump to

Keyboard shortcuts

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