1. Basic environment, flow chart
1) Flow chart
2), install kubectl
on jenkins #View the location of kubectl on the master node
[root@k8s01 ~]# which kubectl
/usr/bin/kubectl
#CP k8s node kubectl file to jenkins
scp 10.0.0.101:/usr/bin/kubectl .
cp ./kubectl /usr/local/bin/
kubectl version
Client Version: version.Info{Major:"1", Minor:"17", GitVersion:"v1.17.9", GitCommit:"4fb7ed12476d57b8437ada90b4f93b17ffaeed99", GitTreeState:"clean", BuildDate:"2020-07-15T16:18:16Z", GoVersion:"go1.13.9", Compiler:"gc", Platform:"linux/amd64"}
#Change the config configuration file cp of the k8s node to jenkins #Execute the [root@localhost kubectl-install]# touch /root/.kube/config
command to view the result
3) Gitlab creates the project benzhupro, and jenkins uses the username and password to pull
4)
Harbor environment preparation #harbor build the warehouse, and jenkins can log in without secret具体可参考: https://blog.51cto.com/keep11/2620067
Second, jenkins creates a pipeline project
# Create Pipeline#pipeline
construction The construction
here is relatively simple, and it will be more detailed in practice. For example, setting parameters, package compilation, yaml file cleaning, and mirror cleaning are all omitted.
Continue to add later
#yaml's configuration file
[root@localhost a1]# cat hello52.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: centos
labels:
app: centos
spec:
replicas: 3
selector:
matchLabels:
app: centos
template:
metadata:
labels:
app: centos
spec:
containers:
- name: centos
image: 10.0.0.181:10080/tools/centos7:pipeline_1_52
imagePullPolicy: Always
ports:
- containerPort: 8037
# dockerfile file
#原镜像
FROM 10.0.0.181:10080/tools/centos7_jdk
#定义标签
LABEL centos:7 centos7:jdk
#解压缩文件到/usr/local
add test.jar /
#变量设置
EXPOSE 8037
ENTRYPOINT ["java", "-jar", "/test.jar"]
3. Verification of release results
2)
node node view the pulled image
3) Pod running status