This is a project for getting notifications from logs of Kubernetes Operator that when a new pod is deployed.
Operator SDK is a tool provided by Operator Framework that allows us to deploy Kubernetes Operators. These operators are used to deploy workloads via Kubernetes API i.e. it helps in deploying workloads by using services of Kubernetes. Read more from the actual link of Operator-SDK.
This project has a 'podset-operator' that contains in own file structure. Now, the main aim of this project is to get a notification in form of text in the logs of the operator pod when any new pod is added to the cluster. This notification is hardcoded in the podset_controller.go file in pkg/controller/podset/. It displays a custom message, name of the pod and details of the pod including its name, namespace and labels.
Please read the official documentation of Operator-SDK to understand its file structure with Go files, how to build the operator with step-by-step process and deploy it.
Changes made in the Operator:
- In podset_types.go file, the contents of the struct{} is changed so that it we can get Pod Names. This file is under pkg/apis/app/v1alpha1/.
- In operator.yaml, the image name is changed to the custom image we have built and pushed to "quay.io" via Docker.
- In podset_controller.go file, a new log variable is made named as
globalLog
. This variable is then used where the pod actually gets created. So, this notification in logs of operator is written inReconcile()
function of this Go file. While creation of the pod, the custom text, name of pod and details of it are also shown in the logs of the operator pod along with other in-built logs. Usekubectl logs
with the operator pod after deploying operator.yaml.
IMP: &coreV1.Pod{}
contains all the basic details of the pod that can be consumed by other functions.
IMP: The log variable globalLog
takes compulsorily 3 arguments i.e. the custom text string, a key and a value. Not mentioning any of these arguments will result in this error: "odd number of arguments passed as key-value pairs for logging"
Actual Operator SDK Practical Documentation: https://docs.okd.io/latest/operators/osdk-getting-started.html
Operator SDK Installation Links: (step-by-step)
- https://www.howtoforge.com/how-to-install-go-programming-language-on-linux-ubuntu-debian-centos/ (install golang from here)
- https://tecadmin.net/install-go-on-ubuntu/ (install GOPATHs from here)
- https://www.linode.com/docs/development/go/install-go-on-ubuntu/ (install GOPATHs from here)
- https://golang.github.io/dep/docs/installation.html
- https://www.atlassian.com/git/tutorials/install-git
- https://github.com/operator-framework/operator-lifecycle-manager/releases
- curl -s "https://raw.githubusercontent.com/\ kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash
Kubenetes Operator links:
- https://medium.com/faun/writing-your-first-kubernetes-operator-8f3df4453234
- https://www.katacoda.com/openshift/courses/operatorframework/go-operator-podset
- https://docs.okd.io/latest/operators/osdk-getting-started.html
- https://medium.com/@shubhomoybiswas/writing-kubernetes-operator-using-operator-sdk-c2e7f845163a
- https://github.com/operator-framework/operator-sdk/blob/master/doc/user/logging.md
- operator-framework/operator-sdk#1758
- https://www.youtube.com/watch?v=Ko_WfXRAypY
Operator SDK Logging: https://github.com/operator-framework/operator-sdk/blob/master/doc/user/logging.md