An implementation of a simple k8s controller:
- Create custom resource
- Launch a RPC worker pod with specific memory, cpu and concurrency limit
docker build -t code-gen .
docker run -it --rm -v `pwd`:/go/src/github.com/willeslau/k8s-controller code-gen bash
# inside docker
/go/src/k8s.io/code-generator/generate-groups.sh all \
github.com/willeslau/k8s-controller/pkg/client \
github.com/willeslau/k8s-controller/pkg/apis \
worker:v1
K8S generated code should be populated.
The code is in internal/controller
, the state machine (work in progress) is
Get the master location by kubectl cluster-info
./controller --kubeconfig ~/.kube/config
- New status is derived only based on current deployment and all the replicas sets but not the "past" states. In this case, try to set the status purely based on the current deployment and worker. Think about what parameters are needed to deduce the status!
- Replica Controller: https://blog.csdn.net/yan234280533/article/details/78312620
- Deployment Controller: https://blog.hdls.me/15763918313590.html
- Deployment Controller Src: https://github.com/kubernetes/kubernetes/blob/27aca3f7c2f06925dd1890cd8b0522b775b0e323/pkg/controller/deployment/deployment_controller.go