Getting Started with Kubernetes API by Kubebuilder

This document just follows a quick tutorial for kubebuilder and learn its behavior.

Install

Install kubebuilder.

curl -L -o kubebuilder https://go.kubebuilder.io/dl/latest/$(go env GOOS)/$(go env GOARCH)
chmod +x kubebuilder && mv kubebuilder /usr/local/bin/

Workaround a first project

At first, create a project and a Guestbook API, and make manifests

kubebuilder init --domain at-ishikawa.github.io --repo at-ishikawa.github.io/at-ishikawa.github.io
kubebuilder create api --group webapp --version v1 --kind Guestbook
# Create Resource [y/n] y
# Create Controller [y/n] y
make manifests

Then you can see its manifest file under config/crd/bases.

Deploy it into a kubernetes cluster

At first, create the namespace on the cluster.

kubectl create namespace kubebuilder

Then install CRD.

make install

Now you can see its CRD

> kubectl get crd | grep guestbook
guestbooks.webapp.at-ishikawa.github.io          2023-02-10T04:41:32Z

Then run a controller in a foreground job

make run

Create a sample resource for CRD

kubectl apply -f config/samples/webapp_v1_guestbook.yaml

Then deploy an image on the cluster

make docker-build docker-push IMG=$registry/$project:$tag
make deploy IMG=$registry/$project:$tag

Then you can see a deployment and pod in the namespace tutorial-system.

> kubectl get deploy -n tutorial-system
NAME                          READY   UP-TO-DATE   AVAILABLE   AGE
tutorial-controller-manager   1/1     1            1           9m57s
> kubectl get pods -n tutorial-system
NAME                                           READY   STATUS    RESTARTS   AGE
tutorial-controller-manager-649cdb6fb5-62nwb   2/2     Running   0          12m

This controller never handle a guestbook crd.

> kubectl get guestbook -n kubebuilder
NAME               AGE
guestbook-sample   2m6s

Architecture

See this page for the overview of the architecture.

  • Manager
    • Controller: Handles an event. Event is first filtered by the predicate and then handled by a reconciler
      • Reconciler contains a logic of a controller for the resource
    • Webhook: Receives an admission request and set the default fields by Defaulter and rejects an invalid object by a Validator
      • They’re mutating admission webhook and validating admission webhook
    • k8s API Client
    • Cache

The example of the reconciling of a controller is as follows, from this page:

  1. Load the named CronJob
  2. List all active jobs, and update the status
  3. Clean up old jobs according to the history limits
  4. Check if we’re suspended (and don’t do anything else if we are)
  5. Get the next scheduled run
  6. Run a new job if it’s on schedule, not past the deadline, and not blocked by our concurrency policy
  7. Requeue when we either see a running job (done automatically) or it’s time for the next scheduled run.

2024

Back to Top ↑

2023

Follow Kubernetes the Hard way

4 minute read

This article was written by just following Kelsey Hightower’s Kubernetes Hardway document to understand Kubernetes internal architecture.

Gcp Billing Analyze

less than 1 minute read

There are a few documents to manage billing data in BigQuery Attribution of committed use discount fees and credits How to export to BigQuery Structur...

Prometheus Metrics Overview on Grafana

1 minute read

In this post, some variables defined in Grafana are used for Prometheus metrics, including $__rate_interval: This article describes the benefit of this va...

Use Google Secret Manager in a GKE cluster

3 minute read

There are an awesome article about the options to use the Google Secret Manager and their pros and cons. In this article, use Secrets Store CSI Driver by fol...

Working around MySQL lock metadata

2 minute read

There are multiple documents about innodb locks on MySQL 5.7: InnoDB locking Locks Set by Different SQL Statements in InnoDB Using InnoDB Transaction ...

Upgrade Windows 10 to Windows 11

3 minute read

I used to use Windows 11, but for some reasons, the OS stopped working and I needed to clean-install it from Windows 10 from windows recovery environment.

Back to Top ↑

2022

MySQL backup and restore

1 minute read

In this article, explain how to backup MySQL database using Percona Xtrabackup. There are two binaries, innobackupex and xtrabackup. innobackupex is a wrappe...

tmux

1 minute read

Basic configuration

Back to Top ↑

2021

MySQL Replication

1 minute read

This configuration is for the version 5.7 and it’s minimum configuration in the official document.

jq cheetsheet

less than 1 minute read

jq is used to parse JSON result, format and output on the cli.

Compare static site generator

less than 1 minute read

There are many web sites to compare static site generator, but they miss some explanations that require to me. For some people, these features are important ...

Back to Top ↑

2020

Getting Started with Kubernetes Deployment

less than 1 minute read

The deployment is many use cases and in this page, they’re not described. For the details for those use cases or the concept of deployment, see official page.

Overview about MySQL Lock

2 minute read

This document is written for MySQL 5.7, so these contents may be not correct for other versions.

MySQL Performance

2 minute read

This document is written for MySQL 5.7, so these contents may be not correct for other versions. In this page, performance_schema is mainly discussed.

Git hooks

less than 1 minute read

Configurations

gitHub pages

3 minute read

Getting Started See Official tutorial for detail steps.

Gitconfig

1 minute read

Configuration The detail for gitconfig is written in official page.

git cli

less than 1 minute read

Written in March 2020.

MySQL Tuner

less than 1 minute read

MySQL Tuner tool This is a tool to review a configuration for MySQL server.

kubectl cheetsheet

less than 1 minute read

Collect recent error logs If the logs are outputted by zap, error messages are aggregated by checking level = error. This log does not work very well if the ...

Introduction to GCP Cloud endpoints

less than 1 minute read

The Cloud endpoint is actually the NGINX proxy which offers the following features on GCP. Authentication and validation Logging and monitoring in GCP

HTTP/2 for Go

1 minute read

http package in golang supports HTTP/2 protocols. It’s automatically configured.

Back to Top ↑

2019

Terraform overview

1 minute read

Basic concepts There are some basic components for terraform.

Protocol Buffers for Go with Gadgets

less than 1 minute read

gogo/protobuf is the library to store some extensions from golang/protobuf in this repository. There are some useful packages that golang/protobuf does not p...

Introduction to GCP Cloud CDN

less than 1 minute read

Target upstream services Cloud CDN can have only GCP load balancer as the upstream services. And GCP load balancer can configure one of followings for backen...

Getting Started with Google closure library

less than 1 minute read

Some JavaScript library depends on Google Closure. If you need to understand the behavior of such a library, you have to know closure. The official document ...

Back to Top ↑