Kubernetes -3-

[TOC]

Status of today:

I’ve been waiting all day for a colleague.

Kubernetes -3-

This is Yann’s 98th post

Part 1: Precommitment

Yesterday, we demonstrated the process of building Deployment with a video and discussed the CRD process and implementation process. Starting with this article, yann makes sure that everyone completes a CRD development experience.

Part 2 project

The official sample

Let’s take a look at the official example program.

The website is as follows:

https://github.com/kubernetes/sample-controller

CRD’s official sample program is very neat and well-behaved. If you’re learning Go, a similar example is a good starting point, rather than a hobby project or a random Hello World on a web page.

Many students do not like to see the official example program, think smelly and long, complex content, version is still old. Like personal blog inside the simplified introduction, the end of a line, the operation of a few results out. To be fair, Yann didn’t like it either. But for the sake of cognitive accuracy, they will force themselves to watch.

Personal projects

Judging from the screenshot above, the official example is a bit more complicated. We created a simpler project from scratch.

Again, create a crd.yaml, paying attention to the content and file path, some values will be used later.

Location: github.com/kubernetes/yann-controller/artifacts/examples/crd.yaml

apiVersion: apiextensions.k8s.io/v1beta1kind: CustomResourceDefinitionmetadata:name: tests.yanncontroller.k8s.iospec:group: yanncontroller.k8s.ioversion: v1alpha1names:  kind: Test  plural: testsscope: NamespacedCopy the code

ApiVersion, kind, metadata, spec and other fixed fields appear in the first article. Similar situations abound in K8S, so let’s just focus on the changes.

This time, the tests and YannController are the complex and grouping names of type names, respectively. You can see this in metadata.

Also note that Test, defined as a type, starts with a capital T.

Engineering documents

Finally, Yann leads us to complete all the files generated by the code. In this article, Yann will only show you the basic file structure, the details of the code and the purpose of each file, which will be explained in later chapters.

We just have to look at the files in the PKG directory. This directory contains two immutable subdirectories apis and signals, representing API and semaphore related files, respectively.

The directories and subdirectories under apis are self-defined, corresponding to the group name prefix YannController in the crd.yaml configuration file and the version number v1alpha1 defined by spec, respectively.

Except for these two directories, the names of other files are fixed. That should make a lot of sense.

Part 3 summary

It’s not a lot today, but it’s more understanding. Understanding the relationship between fields and build projects in CRD. YAML is a top priority. It’s not that difficult once you get to know it.

In the next article, you’ll start parsing the contents of the individual files and building the environment for the official example.

Interactivity is a good practice, and by building a good environment to compile and execute official examples, you can gain insight into the project.

At the same time, having the right environment is very helpful for debugging your own project. If both the project and the environment are not correct, the troubleshooting can be doubly difficult.

This article is published by OpenWrite!

The article published in the platform, and the original format is different, please forgive the inconvenience of reading

The latest content welcome to pay attention to the public account: