https://github.com/trstringer/k8s-controller-core-resource
Base sample for a custom controller in Kubernetes working with core resources
https://github.com/trstringer/k8s-controller-core-resource
kubernetes kubernetes-controllers
Last synced: 7 months ago
JSON representation
Base sample for a custom controller in Kubernetes working with core resources
- Host: GitHub
- URL: https://github.com/trstringer/k8s-controller-core-resource
- Owner: trstringer
- Created: 2018-04-16T19:21:50.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2020-11-05T04:30:53.000Z (about 5 years ago)
- Last Synced: 2025-04-30T07:31:28.498Z (9 months ago)
- Topics: kubernetes, kubernetes-controllers
- Language: Go
- Homepage:
- Size: 7.81 KB
- Stars: 83
- Watchers: 2
- Forks: 46
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Kubernetes Custom Controller - Core 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 pods (in the default namespace). This was created as an exercise to understand how Kubernetes controllers work and interact with the cluster and resources.
## Running
```
$ git clone https://github.com/trstringer/k8s-controller-core-resource
$ cd k8s-controller-core-resource
$ go run *.go
```
## Inspecting resources in the handler
You are welcome to dump the resources themselves in handler but logging would be extremely verbose (and not interactive). I recommend you use a debugger...
```
$ dlv debug
(dlv) b main.ObjectCreated
(dlv) c
```
You can then trigger an event by creating a deployment of nginx...
```
$ kubectl run nginx --image=nginx
```
The breakpoint should be hit and you can analyze in the debugger the object...
```
(dlv) p obj
```