Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to successfully complete the compilation of Kubernetes source code

2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article is about how to successfully complete the Kubernetes source code compilation, the editor feels very practical, so share it with you to learn, I hope you can get something after reading this article, say no more, follow the editor to have a look.

Why compile the source code?

Kubernetes is a great container cluster management platform. Usually, we don't need to modify the K8S code to use it directly. But if we find a problem / defect in the environment, or modify the K8S code according to specific business requirements, such as customizing the StopContainer logic of Kubelet, the pod scheduling logic of kube-scheduler, and so on. In order for the changes to take effect, you need to compile the K8S code.

Kubernetes source code compilation is roughly divided into local binary executable file compilation and docker image compilation. Because in our environment, Kubernetes is run by a Docker container. Therefore, we need to use the latter way of compilation, that is, mirror compilation.

Because the Kubernetes image Dockerfile file for each component service is automatically generated by the Kubernetes source code, the community does not provide an image Dockerfile file for each component. Compiling local binary executables is simple and more straightforward. However, the compilation data of docker image is very little, and it will fail due to some special network reason. Here, we will describe how to successfully complete the K8S image compilation.

Installation dependency

Install Golang

Specify the branch and download the Kubernetes source code (the default $GOPATH directory is / root/go/)

Compiling Kubernetes with local binaries (method 1)

Modify running platform configuration parameters (optional)

Modify hack/lib/golang.sh according to your running platform (linux/amd64) to comment out other platforms in KUBE_SERVER_PLATFORMS,KUBE_CLIENT_PLATFORMS and KUBE_TEST_PLATFORMS except linux/amd64, so as to reduce the compilation time.

Compile source code

Go to the Kubernetes root directory

KUBE_BUILD_PLATFORMS specifies the target platform, WHAT specifies the component to be compiled, and compile-time parameters are passed in through GOFLAGS and GOGCFLAGS, as shown here to compile the kubelet component.

If WHAT is not specified, all are compiled.

Make all is compiled in the local environment.

Make release and make quick-release are compiled in a container and packaged into a docker image.

Compile this part of the kubelet code, or execute make clean & & make WHAT=cmd/kubelet

Check the compilation results

The compilation process is long, please wait patiently, the compiled file is in kubernetes/_output.

Or enter cmd/kubelet (take kubelet as an example)

Execute the go build-v command, and if there is no error, the executable file kubelet is generated

The generated executable file is under the current folder

Docker Image compiling Kubernetes (method 2)

Check the TAG version number of kube-cross

View the debian_iptables_version version number

Here, I use the Auto build function of DockerHub to build the K8s image. Naturally, the base image needed for compilation will be placed on DockerHub (it can also be regarded as a modest contribution to the promotion of domestic K8s source code docker compilation! ).

Remove the-pull in the build/lib/release.sh to prevent the construction image from continuing to pull the image:

Edit the file hack/lib/version.sh

Change KUBE_GIT_TREE_STATE= "dirty" to KUBE_GIT_TREE_STATE= "clean" to make sure the version number is clean.

Execute compilation command

KUBE_BUILD_PLATFORMS=linux/amd64 specifies that the target platform is linux/amd64,GOFLAGS=-v to open verbose logs, and GOGCFLAGS= "- N-l" forbids compilation, optimization and inlining to reduce the size of the executable program.

The compiled K8s Docker image is published in the _ output/release-tars directory as a zipped package.

Use a compiled image

After waiting for the compilation to complete, the compiled binary executable and the docker image tar package are saved in the _ output/release-stage/server/linux-amd64/kubernetes/server/bin/ directory. For example, import the kube-apiserver.tar image and update the kube-apiserver image deployed on the environment.

After the entire compilation process is over, you can now go to the master node and modify the image in the / etc/kubernetes/manifests/kube-apiserver.yaml description file, which will take effect immediately.

The above is how to successfully complete the Kubernetes source code compilation, the editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

  • How to manually add JAR packages downloaded to the local Maven repository

    This article mainly introduces how to download to the local JAR package to manually add to the Maven warehouse, the article is very detailed, has a certain reference value, interested friends must read it!

    © 2024 shulou.com SLNews company. All rights reserved.

    12
    Report