Welcome to my GitHub

Github.com/zq2599/blog…

Content: all original article classification summary and supporting source code, involving Java, Docker, Kubernetes, DevOPS, etc.;

Links to articles

  1. Kubebuilder: Preparation
  2. Kubebuilder For the first time
  3. Kubebuilder 3: Quick overview of basic knowledge
  4. Operator requirements specification and design
  5. Kubebuilder operator code
  6. Kubebuilder Six: Build deployment run
  7. Kubebuilder: Webhook
  8. Kubebuilder: How do you do

About kubebuilder

  1. In the actual work, kubernetes resources to perform a variety of personalized configuration and control is very common requirements, such as how to control the number of copies, master slave relationship, and a variety of custom resource control;
  2. For the above requirements, very suitable for use Operator mode to solve, here are the official introduction to the Operator: kubernetes. IO/useful/docs/con… , the execution flow of Operator mode is as follows:

3. In order to simplify Operator development, we can choose some existing open source tools, kubeBuilder is one of them, “KubeBuilder Actual Combat” series is the practice of this tool from shallow to deep;

This paper gives an overview of

As the beginning of “KubeBuilder Actual Combat” series, in addition to the previous simple description of KubeBuilder, will also list the general environment information of the whole actual combat, and the software version involved, and then build kubeBuilder development environment, in general, need to do the following preparations, To start kubeBuilder:

  1. Kubectl installation and configuration, so that you can operate the Kubernetes environment on the KubeBuilder computer;
  2. Install golang
  3. Install the docker
  4. Install kustomize
  5. Install kubebuilder

Environmental information

As shown below, the whole combat environment is composed of two computers:

  1. Kubernetes computer: Hostname is k8S, which runs version 1.20 of Kubernetes. Kubernetes deployment is not the focus of this article.
  2. Kubebuilder computer: the operating system is CentooS-7.9.2009 and hostname is KubeBuilder. Our actual combat is operated on this computer.
  3. Kubebuilder version: 2.3.1
  4. Go version: 1.15.6
  5. Docker version: 19.03.13
  6. To save trouble, all operations are performed using the root account;

Kubectl installation and configuration

  1. Run the following command to install it online:
curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
Copy the code

If you don’t have access to the above address, can be downloaded here (0 points) : download.csdn.net/download/bo…

  1. Kubectl file download to Linux machine, execute command chmod +x./kubectl, give file executable permission;
  2. Execute the following command to move kubectl to a globally accessible directory:
mv ./kubectl /usr/local/bin/kubectl
Copy the code
  1. Create ~/.kube/ directory;
  2. Log in to THE K8S computer at/.kube/Copy the config file to /. Kube/on your KubeBuilder PC.
  3. Kubectl = kubernetes; kubectl = kubernetes;
[root@kubebuilder ~]# kubectl get nodes -o wide
NAME   STATUS   ROLES                  AGE   VERSION   INTERNAL-IP       EXTERNAL-IP   OS-IMAGE                KERNEL-VERSION                CONTAINER-RUNTIME
k8s    Ready    control-plane,master   33m   v1.20.2   192.168.133.211   <none>        CentOS Linux 7 (Core)   3.10.0-1160.11.1.el7.x86_64   docker://19.3.13
[root@kubebuilder ~]# 
[root@kubebuilder ~]# kubectl get pod --all-namespaces
NAMESPACE     NAME                          READY   STATUS    RESTARTS   AGE
kube-system   coredns-7f89b7bc75-fw928      1/1     Running   0          33m
kube-system   coredns-7f89b7bc75-tv7tk      1/1     Running   0          33m
kube-system   etcd-k8s                      1/1     Running   0          33m
kube-system   kube-apiserver-k8s            1/1     Running   0          33m
kube-system   kube-controller-manager-k8s   1/1     Running   0          33m
kube-system   kube-flannel-ds-q9f64         1/1     Running   0          32m
kube-system   kube-proxy-clmbf              1/1     Running   0          33m
kube-system   kube-scheduler-k8s            1/1     Running   0          33m
Copy the code

Install golang

  1. Install necessary applications:
yum install unzip tree wget gcc gcc-c++ kernel-devel -y
Copy the code
  1. Install Golang with the script I prepared and set up the environment variables:
curl -o install-go.sh \
https://raw.githubusercontent.com/zq2599/blog_demos/master/files/install-go.sh \
&& chmod a+x ./install-go.sh \
&& ./install-go.sh
Copy the code
  1. The hello.go file is successfully executed, indicating that the GO environment is successfully deployed, and the output environment variables are normal:
. 5. create go source file package main import "fmt" func main() { fmt.Println("Hello world!" ) } 6. run hello.go Hello world! Go1.15.6 Install and Check finishedCopy the code
  1. Execute source.bashrc to ensure that the environment variables in the current shell environment are in effect;

Install the docker

  1. Execute the following command to complete the installation and startup of docker:
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum list docker-ce --showduplicates | sort -r
yum -y install docker-ce-19.03.13
systemctl start docker
systemctl enable docker
Copy the code
  1. Verify the successful installation:
[root@kubebuilder ~]# Docker version Client: Docker Engine - Community version: 20.10.2 API version: 1.40 Go version: Go1.13.15 Git commit: 2291f61 Built: Mon Dec 28 16:17:48 2020 OS/Arch: Linux/AMd64 Context: default Experimental True Server: Docker Engine - Community Engine: Version: 19.03.13 API Version: 1.40 (minimum Version 1.12) Go Version: Go1.13.15 Git commit: 4484c46d9d Built: Wed Sep 16 17:02:21 2020 OS/Arch: Linux /amd64 Experimental: false containerd: Version: 1.4.3 GitCommit: 269548 fa27e0089a8b8278fc4fc781d7f65a939b runc: Version: 1.0.0 - rc92 GitCommit: Ff819c7e9184c13b7c2607fe6c30ae19403a7aff docker - init: Version: 0.18.0 GitCommit: fec3683Copy the code
  1. Otherwise, the image download takes a long time and often times out. Run the following command to set the image acceleration to take effect:
mkdir -p /etc/docker
tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://registry.docker-cn.com"]
}
EOF
systemctl daemon-reload
systemctl restart docker

Copy the code

Install kustomize

Kustomize is required for configuration management in the following operations. To install it, run the following command:

mkdir -p $GOPATH/bin
cd $GOPATH/bin
GOBIN=$(pwd)/ GO111MODULE=on go get sigs.k8s.io/kustomize/kustomize/v3
Copy the code

Install kubebuilder

  1. The following script uses the go command to determine the current system and CPU architecture, then goes to the server to download the corresponding KubeBuilder file, and then sets the environment variables:
OS = $(go env GOOS) arch = $(go env GOARCH) curl -l https://go.kubebuilder.io/dl/2.3.1/$} {the OS / ${arch} | tar - xz - C/TMP/mv / TMP/kubebuilder_2. 3.1 _ ${} OS _ ${arch} / usr/local/kubebuilder export PATH = $PATH: / usr/local/kubebuilder/binCopy the code
  1. Run the following command to confirm the installation:
[root@kubebuilder ~]# kubebuilder version Version: Version. The version {KubeBuilderVersion: "2.3.1," KubernetesVendor: "1.16.4", GitCommit:"8b53abeb4280186e494b726edf8f54ca7aa64a49", BuildDate:"2020-03-26T16:42:00Z", GoOs:"unknown", GoArch:"unknown"}Copy the code
  • At this point, kubeBuilder development environment preparation work is completed, the next chapter we formally entered the development of combat, together to learn wonderful Kubernetes operator;

You are not alone, Xinchen original accompany all the way

  1. Java series
  2. Spring series
  3. The Docker series
  4. Kubernetes series
  5. Database + middleware series
  6. The conversation series

Welcome to pay attention to the public number: programmer Xin Chen

Wechat search “programmer Xin Chen”, I am Xin Chen, looking forward to enjoying the Java world with you…

Github.com/zq2599/blog…