jenkins pipeline 發佈應用

一、基礎環境、流程圖
1)流程圖

jenkins pipeline 發佈應用

2)、jenkins上安裝kubectl
#主節點上查看kubectl位置

[root@k8s01 ~]# which kubectl
/usr/bin/kubectl

#將k8s節點的kubectl文件cp至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"}

#將k8s節點的config配置文件cp 至jenkins
[root@localhost kubectl-install]# touch /root/.kube/config
jenkins pipeline 發佈應用
#執行命令查看結果
jenkins pipeline 發佈應用



3)gitlab創建項目benzhupro,並且jenkins使用用戶名密碼可拉取
jenkins pipeline 發佈應用

4) harbor環境準備
#harbor 建好倉庫,並且jenkins 可以免密登陸
具體可參考: https://blog.51cto.com/keep11/2620067

二、jenkins創建pipeline項目
#創建流水線
jenkins pipeline 發佈應用
#pipeline 構建
此處構建比較簡單,實際中會更加詳細。比如設置參數,打包編譯、yaml文件清理、鏡像清理都省略。
後續再繼續添加
jenkins pipeline 發佈應用





#yaml的配置文件

[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 文件

#原鏡像
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"]

三、發佈結果驗證
jenkins pipeline 發佈應用

jenkins pipeline 發佈應用

jenkins pipeline 發佈應用

jenkins pipeline 發佈應用

2)
node節點查看拉取的鏡像
jenkins pipeline 發佈應用

3)pod運行狀態
jenkins pipeline 發佈應用

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章