Skip to content

Base sample for a custom controller in Kubernetes working with custom resources

Notifications You must be signed in to change notification settings

resouer/k8s-controller-custom-resource

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kubernetes Custom Controller - Custom Resource Handling

Note: the source code is verbosely commented, so the source is meant to be read and to teach

What is 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:

$ git clone https://github.com/resouer/k8s-controller-custom-resource
$ cd k8s-controller-custom-resource

Prepare build environment:

$ go get github.com/tools/godep
$ godep restore

Build and run:

$ go build -o samplecrd-controller .
$ ./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:

$ kubectl apply -f crd/network.yaml

You can then trigger an event by creating a Network API instance:

$ kubectl apply -f example/example-network.yaml

CURD the Network API instance, and check the logs of controller.

Enjoy!

About

Base sample for a custom controller in Kubernetes working with custom resources

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%