Building Kubernetes from source – part 1
Perhaps one of the most overlooked aspects of Kubernetes is the CI/CD pipeline that is used for k8s releases.
Perhaps it is precisely due to the simplicity and reliability of the assembly process, which is built mainly on bash scripts And instructions make, a project that is well over 2 million lines of code can be built from source, tested, and released by executing a single target in the Makefile.
git clone https://github.com/kubernetes/kubernetes.git
make -f build/root/Makefile all WHAT=cmd/kubelet kube-proxy kube-apiserver kube-controller-manager kube-scheduler kubectl GOFLAGS=-v
As an example of an assembly pipeline, we will use one of the most popular CI tools – Jenkins.
At the same time, due to the fact that all assembly logic and tests were prudently placed in scripts and make-files, you can not be tied to any particular framework for continuous integration. Any other tool can be used instead of Jenkns.
jenkinsfile
pipeline {
agent any
stages {
stage('Build') {
steps {
/// Клонируем репозиторий кубернетес
git 'https://github.com/kubernetes/kubernetes.git'
/// Чтобы не было конфликтов, перед запуском сборки убеждаемся что директория _output очищена
sh "make -f build/root/Makefile clean"
/// Выбираем для сборки только основные компоненты кубернетес
sh "make -f build/root/Makefile all WHAT=cmd/kubelet kube-proxy kube-apiserver kube-controller-manager kube-scheduler kubectl GOFLAGS=-v"
}
}
}
/// В блоке post можно указывать условия которые будут всегда выполнятся после завершения задания jenkins
/// В данном случае мы инструктируем jenkins сохранять все файлы в целевой директории
post {
always {
archiveArtifacts artifacts: '_output/local/go/bin/**/*.*'
}
}
}