Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bbbmj/k8s-crd-controller-example
Base example for a custom controller in Kubernetes working with custom resources. Based on https://github.com/resouer/k8s-controller-custom-resource.
https://github.com/bbbmj/k8s-crd-controller-example
code-generator crd custom-control custom-resource-definition custom-resources kubernetes kubernetes-controller
Last synced: about 1 month ago
JSON representation
Base example for a custom controller in Kubernetes working with custom resources. Based on https://github.com/resouer/k8s-controller-custom-resource.
- Host: GitHub
- URL: https://github.com/bbbmj/k8s-crd-controller-example
- Owner: bbbmj
- License: apache-2.0
- Created: 2018-10-23T03:52:10.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-10-23T08:51:44.000Z (over 6 years ago)
- Last Synced: 2024-11-16T20:42:39.773Z (3 months ago)
- Topics: code-generator, crd, custom-control, custom-resource-definition, custom-resources, kubernetes, kubernetes-controller
- Language: Go
- Homepage:
- Size: 4.12 MB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# k8s-crd-controller-example
Based on `https://github.com/resouer/k8s-controller-custom-resource`.
**Note**: the source code is _verbosely_ commented, so the source is meant to be read and to teach.
## What's this?
An example of a custom Kubernetes controller that's only purpose is to watch for the creation, updating, or deletion of all custom resource of type `Network` (in the all namespaces). This was created as an exercise to understand how Kubernetes controllers work and interact with the cluster and resources.
## Running
Clone repo:
```bash
git clone https://github.com/bbbmj/k8s-crd-controller-example
cd k8s-crd-controller-example
```Build and run:
```bash
go build -o bin/samplecrd-controller ./cmd/
./bin/samplecrd-controller -kubeconfig=$HOME/.kube/config -alsologtostderr=true
```You can also use `samplecrd-controller` to create a Deployment and run it in Kubernetes. Note in this case, you don't need to specify `-kubeconfig` in CMD as default `InClusterConfig` will be used.
## Usage
You should create the CRD of Network first:
```bash
kubectl apply -f artifacts/network-crd.yaml
```You can then trigger an event by creating a Network API instance:
```bash
kubectl apply -f artifacts/my-network.yaml
```CURD the Network API instance, and check the logs of controller.
Enjoy!