1
0
Fork 0
mirror of https://github.com/kubernetes-sigs/node-feature-discovery.git synced 2024-12-14 11:57:51 +00:00

Makefile: create default yamls, configurable namespace

- Create default yamls for deploying master and worker.
- Use kube-system namespace by default.
- Configurable namespace:
  make IMAGE_REGISTRY=myhost:5000 K8S_NAMESPACE=my-nfd-devel
This commit is contained in:
Antti Kervinen 2019-05-28 17:13:52 +03:00
parent 14f98508ba
commit 9b96407b26
7 changed files with 72 additions and 29 deletions

View file

@ -1,4 +1,5 @@
.PHONY: all test
.PHONY: all test yamls
.FORCE:
IMAGE_BUILD_CMD := docker build
@ -9,14 +10,28 @@ IMAGE_NAME := node-feature-discovery
IMAGE_TAG_NAME := $(VERSION)
IMAGE_REPO := $(IMAGE_REGISTRY)/$(IMAGE_NAME)
IMAGE_TAG := $(IMAGE_REPO):$(IMAGE_TAG_NAME)
K8S_NAMESPACE := kube-system
yaml_templates := $(wildcard *.yaml.template)
yaml_instances := $(patsubst %.yaml.template,%.yaml,$(yaml_templates))
all: image
image:
image: yamls
$(IMAGE_BUILD_CMD) --build-arg NFD_VERSION=$(VERSION) \
-t $(IMAGE_TAG) ./
yamls: $(yaml_instances)
%.yaml: %.yaml.template .FORCE
@echo "$@: namespace: ${K8S_NAMESPACE}"
@echo "$@: image: ${IMAGE_TAG}"
@sed -E \
-e s',^(\s*)name: node-feature-discovery # NFD namespace,\1name: ${K8S_NAMESPACE},' \
-e s',^(\s*)image:.+$$,\1image: ${IMAGE_TAG},' \
-e s',^(\s*)namespace:.+$$,\1namespace: ${K8S_NAMESPACE},' \
$< > $@
mock:
mockery --name=FeatureSource --dir=source --inpkg --note="Re-generate by running 'make mock'"
mockery --name=APIHelpers --dir=pkg/apihelper --inpkg --note="Re-generate by running 'make mock'"

View file

@ -436,16 +436,18 @@ If you want to use the latest development version (master branch) you need to
#### nfd-master
Nfd-master runs as a DaemonSet, by default in the master node(s) only. You can
use the template spec provided to deploy nfd-master. If deploying a custom
image, you need to update the template to use the correct image (for the latest
released version, omit the `sed` part):
Nfd-master runs as a DaemonSet, by default in the master node(s)
only. You can use the template spec provided to deploy nfd-master, or
use `nfd-master.yaml` generated by `Makefile`. The latter includes
`image:` and `namespace:` definitions that match the latest built
image. Example:
```
sed -E s',^(\s*)image:.+$,\1image: <YOUR_IMAGE_REPO>:<YOUR_IMAGE_TAG>,' nfd-master.yaml.template > nfd-master.yaml
make IMAGE_TAG=<IMAGE_TAG>
docker push <IMAGE_TAG>
kubectl create -f nfd-master.yaml
```
Nfd-master listens for connections from nfd-worker(s) and connects to the
Kubernetes API server to adds node labels advertised by them.
Kubernetes API server to add node labels advertised by them.
If you have RBAC authorization enabled (as is the default e.g. with clusters
initialized with kubeadm) you need to configure the appropriate ClusterRoles,
@ -456,12 +458,14 @@ labels. The provided template will configure these for you.
#### nfd-worker
Nfd-worker is preferably run as a Kubernetes DaemonSet. There is an
example spec that can be used as a template, or, as is when just trying out the
service. Similarly to nfd-master above, if using a custom-built image you need
to update the template with the correct image (for the latest release, omit the
`sed` part):
example spec (`nfd-worker-daemonset.yaml.template`) that can be used
as a template, or, as is when just trying out the service. Similarly
to nfd-master above, the `Makefile` also generates
`nfd-worker-daemonset.yaml` from the template that you can use to
deploy the latest image. Example:
```
sed -E s',^(\s*)image:.+$,\1image: <YOUR_IMAGE_REPO>:<YOUR_IMAGE_TAG>,' nfd-worker-daemonset.yaml.template > nfd-worker-daemonset.yaml
make IMAGE_TAG=<IMAGE_TAG>
docker push <IMAGE_TAG>
kubectl create -f nfd-worker-daemonset.yaml
```
@ -475,7 +479,7 @@ Feature discovery can alternatively be configured as a one-shot job. There is
an example script in this repo that demonstrates how to deploy the job in the cluster.
```
./label-nodes.sh [<YOUR_IMAGE_REPO>:<YOUR_IMAGE_TAG>]
./label-nodes.sh [<IMAGE_TAG>]
```
The label-nodes.sh script tries to launch as many jobs as there are Ready nodes.
@ -592,7 +596,7 @@ make
Optional, this example with Docker.
```
docker push <image registry>/<image-name>:<version>
docker push <IMAGE_TAG>
```
**Change the job spec to use your custom image (optional):**
@ -614,6 +618,7 @@ name of the resulting container image.
| IMAGE_TAG_NAME | Container image tag name | &lt;nfd version&gt;
| IMAGE_REPO | Container image repository to use | &lt;IMAGE_REGISTRY&gt;/&lt;IMAGE_NAME&gt;
| IMAGE_TAG | Full image:tag to tag the image with | &lt;IMAGE_REPO&gt;/&lt;IMAGE_NAME&gt;
| K8S_NAMESPACE | nfd-master and nfd-worker namespace | kube-system
For example, to use a custom registry:
```
@ -672,7 +677,7 @@ This is open source software released under the [Apache 2.0 License](LICENSE).
## Demo
A demo on the benefits of using node feature discovery can be found in [demo](demo/).
A demo on the benefits of using node feature discovery can be found in [demo](demo/).
<!-- Links -->
[cpuid]: http://man7.org/linux/man-pages/man4/cpuid.4.html

View file

@ -1,23 +1,36 @@
#!/usr/bin/env bash
this=`basename $0`
if [ $# -gt 1 ]; then
if [ $# -gt 1 ] || [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
echo Usage: $this [IMAGE[:TAG]]
exit 1
fi
IMAGE=$1
if [ -n "$IMAGE" ]; then
if [ ! -f nfd-worker-job.yaml ]; then
make IMAGE_TAG=$IMAGE nfd-worker-job.yaml
else
# Keep existing nfd-worker-job.yaml, only update image.
sed -E "s,^(\s*)image:.+$,\1image: $IMAGE," -i nfd-worker-job.yaml
fi
fi
if [ ! -f nfd-worker-job.yaml ]; then
# Missing image info for the labeling job.
echo "nfd-worker-job.yaml missing."
echo "Run 'make nfd-worker-job.yaml', use the template or provide IMAGE (see --help)."
exit 2
fi
# Get the number of nodes in Ready state in the Kubernetes cluster
NumNodes=$(kubectl get nodes | grep -i ' ready ' | wc -l)
# We set the .spec.completions and .spec.parallelism to the node count
# We request a specific hostPort in the job spec to limit the number of pods
# that run on a node to one. As a result, one pod runs on each node in parallel
# We set the NODE_NAME environemnt variable to get the Kubernetes node object.
sed -e "s/COMPLETION_COUNT/$NumNodes/" \
-e "s/PARALLELISM_COUNT/$NumNodes/" \
nfd-worker-job.yaml.template > nfd-worker-job.yaml
if [ -n "$1" ]; then
sed -E "s,^(\s*)image:.+$,\1image: $1," -i nfd-worker-job.yaml
fi
# We set the NODE_NAME environment variable to get the Kubernetes node object.
sed -e "s/completions:.*$/completions: $NumNodes/" \
-e "s/parallelism:.*$/parallelism: $NumNodes/" \
-i nfd-worker-job.yaml
kubectl create -f nfd-worker-job.yaml

View file

@ -5,7 +5,7 @@ apiVersion: v1
kind: ServiceAccount
metadata:
name: nfd-master
namespace: default
namespace: node-feature-discovery
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
@ -32,7 +32,7 @@ roleRef:
subjects:
- kind: ServiceAccount
name: nfd-master
namespace: default
namespace: node-feature-discovery
---
apiVersion: apps/v1
kind: DaemonSet
@ -40,6 +40,7 @@ metadata:
labels:
app: nfd
name: nfd
namespace: node-feature-discovery
spec:
selector:
matchLabels:

View file

@ -1,8 +1,13 @@
apiVersion: v1
kind: Namespace
metadata:
name: node-feature-discovery # NFD namespace
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: nfd-master
namespace: default
namespace: node-feature-discovery
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
@ -29,7 +34,7 @@ roleRef:
subjects:
- kind: ServiceAccount
name: nfd-master
namespace: default
namespace: node-feature-discovery
---
apiVersion: apps/v1
kind: DaemonSet
@ -37,6 +42,7 @@ metadata:
labels:
app: nfd-master
name: nfd-master
namespace: node-feature-discovery
spec:
selector:
matchLabels:
@ -94,6 +100,7 @@ apiVersion: v1
kind: Service
metadata:
name: nfd-master
namespace: node-feature-discovery
spec:
selector:
app: nfd-master

View file

@ -4,6 +4,7 @@ metadata:
labels:
app: nfd-worker
name: nfd-worker
namespace: node-feature-discovery
spec:
selector:
matchLabels:

View file

@ -4,6 +4,7 @@ metadata:
labels:
app: node-feature-discovery
name: nfd-worker
namespace: node-feature-discovery
spec:
completions: COMPLETION_COUNT
parallelism: PARALLELISM_COUNT