From 365d38a7aabd1691b0f82d32edc22dbbf723d970 Mon Sep 17 00:00:00 2001 From: Gautam Prajapati Date: Fri, 17 Jul 2020 12:31:26 +0530 Subject: [PATCH 1/3] Add instructions to run operator and see various features in action --- README.md | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index cd92079..2aa0a70 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Celery-Kubernetes-Operator(WIP) A basic Celery operator written in Python. To be used to manage Celery applications on a Kubernetes cluster. It is being built as a demo project to proposed EuroPython 2020 [proposal](https://ep2020.europython.eu/talks/BbvZjFa-advanced-infrastructure-management-in-kubernetes-using-python/). -Beyond the conference, it'll be pursued to be a production ready project. +Beyond the conference based on feedback, it'll be pursued to be a production ready project. Please report an issue for improvement suggestions/feedback. This operator is being written with the help of [KOPF](https://github.com/zalando-incubator/kopf) framework open sourced by Zalando SE. @@ -15,6 +15,29 @@ It aims to have following things in place- - DELETE - Deletes the custom resource and all the child deployments 3. Keep a watch on important metrics(queue length, cpu, memory etc) using flower(and native K8s solutions) to autoscale/downscale the number of workers on specified constraints. +# Instructions to see this operator in action + +1. Install [minikube](https://kubernetes.io/docs/tasks/tools/install-minikube/). This project is developed and tested only on minikube as of now. +2. Run `minikube start --driver=hyperkit` to start minikube. It is going to download VM boot image and setup a single node kubernetes cluster for you. + +We need to build our docker images for celery app and the operator. They are going to be used in creating worker, flower and operator deployments. + +3. Switch to minikube docker daemon using `eval $(minikube -p minikube docker-env)` in your shell. This is important so that minikube doesn't try to pull images from remote registry. We're going to use our locally built images for the demo. Not using any remote registry. Image pull policy in all deployment spec is set to `Never` right now +4. For building operator image, run `docker build -t celery-operator .` +5. For building celery-flask example application image, run `docker build -t example-image -f example/Dockerfile .` +6. Apply celery CRD using `kubectl apply -f deploy/crd.yaml`. It'll enable Kubernetes to understand the custom resource named Celery +7. Create the custom resource(CR) using `kubectl apply -f deploy/cr.yaml`. It'll create the Celery resource for you. +8. Apply `kubectl apply -f deploy/rbac.yaml` to give operator necessary permissions to watch, create and modify resources on minikube K8s cluster +9. We need to setup a redis deployment in the cluster before deploying the operator. As soon as worker and flower deployment come up, they'd need a broker ready to connect to. We're using redis as broker for the demo. A deployment and service for redis can be created using `kubectl apply -f templates/static/redis-master.yaml`. +10. Now to take action on newly created CR, we are going to deploy operator. Apply `kubectl apply -f deploy/operator.yaml` to setup the operator deployment. + +As soon as pod for the operator comes up, it notices the Celery resource and handles the creation event to setup worker deployments flower deployment and exposing Flower svc as a NodePort type to be accessed from outside the cluster. +You could do `minikube service celery-crd-example-flower --url` to get the url, open it in web browser to see if the newly created workers are in healthy state or not. + +To see the custom autoscaling in action, we need to create another deployment - A flask application that keeps pushing messages in the redis broker continuously. + +11. Do `kubectl apply -f templates/static/flask-example.yaml` to run a flask example which is going to fill the queue with messages. As soon as each queue length goes beyond the average specified in CR, it'll trigger autoscaling of workers. If you delete the flask deployment(`kubectl delete -f templates/static/flask-example.yaml`), number of messages in queue will come down and hence decreasing the number of workers as well in the process. + # Directory Structure # Inspiration From c0080bc2bac3606720a1a16ebb8ca6a2f7bd5e72 Mon Sep 17 00:00:00 2001 From: Gautam Prajapati Date: Sun, 16 Aug 2020 16:27:45 +0530 Subject: [PATCH 2/3] Set theme jekyll-theme-cayman --- docs/_config.yml | 1 + docs/index.md | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 docs/_config.yml create mode 100644 docs/index.md diff --git a/docs/_config.yml b/docs/_config.yml new file mode 100644 index 0000000..c419263 --- /dev/null +++ b/docs/_config.yml @@ -0,0 +1 @@ +theme: jekyll-theme-cayman \ No newline at end of file diff --git a/docs/index.md b/docs/index.md new file mode 100644 index 0000000..e2ab33d --- /dev/null +++ b/docs/index.md @@ -0,0 +1,37 @@ +## Welcome to GitHub Pages + +You can use the [editor on GitHub](https://github.com/brainbreaker/Celery-Kubernetes-Operator/edit/master/docs/index.md) to maintain and preview the content for your website in Markdown files. + +Whenever you commit to this repository, GitHub Pages will run [Jekyll](https://jekyllrb.com/) to rebuild the pages in your site, from the content in your Markdown files. + +### Markdown + +Markdown is a lightweight and easy-to-use syntax for styling your writing. It includes conventions for + +```markdown +Syntax highlighted code block + +# Header 1 +## Header 2 +### Header 3 + +- Bulleted +- List + +1. Numbered +2. List + +**Bold** and _Italic_ and `Code` text + +[Link](url) and ![Image](src) +``` + +For more details see [GitHub Flavored Markdown](https://guides.github.com/features/mastering-markdown/). + +### Jekyll Themes + +Your Pages site will use the layout and styles from the Jekyll theme you have selected in your [repository settings](https://github.com/brainbreaker/Celery-Kubernetes-Operator/settings). The name of this theme is saved in the Jekyll `_config.yml` configuration file. + +### Support or Contact + +Having trouble with Pages? Check out our [documentation](https://docs.github.com/categories/github-pages-basics/) or [contact support](https://github.com/contact) and we’ll help you sort it out. From 710998809e212c57fd5d12dbb2fd5ffbe273ff11 Mon Sep 17 00:00:00 2001 From: Gautam Prajapati Date: Sun, 16 Aug 2020 16:46:31 +0530 Subject: [PATCH 3/3] Update index.md --- docs/index.md | 35 ++++------------------------------- 1 file changed, 4 insertions(+), 31 deletions(-) diff --git a/docs/index.md b/docs/index.md index e2ab33d..2d596d0 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,37 +1,10 @@ -## Welcome to GitHub Pages +## Celery Kubernetes Operator(WIP) -You can use the [editor on GitHub](https://github.com/brainbreaker/Celery-Kubernetes-Operator/edit/master/docs/index.md) to maintain and preview the content for your website in Markdown files. +A Kubernetes operator to manage Celery clusters. It started with being built as a demo project to EuroPython 2020 [talk](https://youtu.be/MoVHxRZ1688?t=9882) around automating infrastructure management in Kubernetes while staying in Python ecosystem. -Whenever you commit to this repository, GitHub Pages will run [Jekyll](https://jekyllrb.com/) to rebuild the pages in your site, from the content in your Markdown files. +Please report an issue for improvement suggestions or feedback. This operator is being written with the help of [KOPF](https://github.com/zalando-incubator/kopf) framework open sourced by Zalando SE. -### Markdown - -Markdown is a lightweight and easy-to-use syntax for styling your writing. It includes conventions for - -```markdown -Syntax highlighted code block - -# Header 1 -## Header 2 -### Header 3 - -- Bulleted -- List - -1. Numbered -2. List - -**Bold** and _Italic_ and `Code` text - -[Link](url) and ![Image](src) -``` - -For more details see [GitHub Flavored Markdown](https://guides.github.com/features/mastering-markdown/). - -### Jekyll Themes - -Your Pages site will use the layout and styles from the Jekyll theme you have selected in your [repository settings](https://github.com/brainbreaker/Celery-Kubernetes-Operator/settings). The name of this theme is saved in the Jekyll `_config.yml` configuration file. ### Support or Contact -Having trouble with Pages? Check out our [documentation](https://docs.github.com/categories/github-pages-basics/) or [contact support](https://github.com/contact) and we’ll help you sort it out. +Please reach out on [twitter](https://twitter.com/28gautam97) or email [28gautam97@gmail.com](mailto:28gautam97@gmail.com).