Thursday, November 10, 2022
Apex Ords Operator for Kubernetes
Friday, August 20, 2021
Tip: what are the GVK GVR CRD CR Scheme in Kuberentes Core API
- GVK stands for Group Version Kind
- Each Kind in K8S has Group and Version. i.e. Kind "Pod" is in Group "core" , Version "v1". Refer to official API doc
- GVK is defined to associate Group, Version and Kind
- Each GVK map to a given root Go type in the package
- Source code definition is here
- GVR stands for Group Version Resource
- GVR is a "use" or "instance" of GVK in the K8S API
- The command "kubectl api-resources" gives us a list of GVR in the K8S cluster
- CRD stands for Custom Resource Definition
- Each CRD is like Kind in K8S, so it also has Group, Version
- CRD is the extension of the K8S API. Refer to official doc
- Once it is defined, it acts like GVK in K8S API.
- CR stands for Custom Resource
- CR is a "use" or "instance" of CRD in the K8S API
- Once it is instantiated, it acts like GVR in K8S API.
- The command "kubectl api-resources" gives us a list including both GVR and CR in the cluster.
- The scheme is defined to keep track of a given GO type mapping to a given GVK.
- For example, we define myexample.io/api/v1.mykind{}
- The scheme is going to map it to the API group we defined in CRD: batchv1.myexample.io/v1
- {
kind: mykind
apiVersion: batchv1.myexample.io/v1
} - Source code definition is here.
Friday, July 16, 2021
Tip: How to get Go Client in Kubernetes Operator Reconcile()
Requirement:
When we build a K8S operator via kubebuilder, we often need to interact with Control Plane. By default, we use controller-runtime client
However, when we use this client to fulfil some functions of kubectl i.e. drain, we hit an error:
cannot use r.Client (variable of type client.Client) as kubernetes.Interface value in struct literal: missing method AdmissionregistrationV1
Solution:
The error indicates the controller-runtime client does not implement method AdmissionregistrationV1, so we can't use it, instead, we init a new GO Client in the reconcile(). Sample code is like
"k8s.io/client-go/kubernetes"ctrlconfig "sigs.k8s.io/controller-runtime/pkg/client/config"cfg, err := ctrlconfig.GetConfig()if err != nil {log.Log.Error(err, "unable to get kubeconfig")return err}kubeclientset, err := kubernetes.NewForConfig(cfg)if err != nil {return err}
Friday, June 25, 2021
Kubebuilder Controller-runtime client_go_adapter.go Error
Symptom:
We hit below error when we build an operator via kubebuilder 3.1 + controller runtime v0.8.3 + kuberentes 1.20.2
./../../pkg/mod/sigs.k8s.io/controller-runtime@v0.8.3/pkg/metrics/client_go_adapter.go:134:3: cannot use &latencyAdapter{...} (type *latencyAdapter) as type metrics.LatencyMetric in field value:
*latencyAdapter does not implement metrics.LatencyMetric (wrong type for Observe method)
have Observe(string, url.URL, time.Duration)
want Observe(context.Context, string, url.URL, time.Duration)
../../../pkg/mod/sigs.k8s.io/controller-runtime@v0.8.3/pkg/metrics/client_go_adapter.go:135:3: cannot use &resultAdapter{...} (type *resultAdapter) as type metrics.ResultMetric in field value:
*resultAdapter does not implement metrics.ResultMetric (wrong type for Increment method)
have Increment(string, string, string)
want Increment(context.Context, string, string, string)
Solution:
Monday, June 10, 2019
Error: the server could not find the requested resource
Symptom:
We follow the https://book.kubebuilder.io/ and create an exampleIt error out when we do "make run"
the server could not find the requested resource (put cronjobs.batch.mycrontab cronjob-sample)"}
Solution:
After i check cronjob_types.go , add below, issue is fixed// +kubebuilder:subresource:status
type CronJob struct {
Saturday, February 16, 2019
Tips of How to Understand CustomResourceDefinition in K8S
The basic logic is :
- We define what CRD we would like to use , ie mysql-operator in github, postgres-operator....
- We implement the business logic via GO
- We create yaml files to use the CRD we define