一、安装jdk
[root@k8s-node-2 opt]# rpm -ivh jdk-8u102-linux-x64.rpm
二、安装tomcat
[root@k8s-node-2 opt]# mkdir app
[root@k8s-node-2 opt]# tar xf apache-tomcat-8.0.27.tar.gz -C app/
三、删除默认站点下的文件,文件改名
[root@k8s-node-2 opt]# rm -rm app/apache-tomcat-8.0.27/webapps/*
[root@k8s-node-2 opt]# mv jenkins.war app/apache-tomcat-8.0.27/webapps/ROOT.war
四、解压jenkin-data软件包
[root@k8s-node-2 opt]# tar xf jenkin-data.tar.gz -C /root/
[root@k8s-node-2 opt]# ls /root/.jenkins/
config.xml jenkins.install.InstallUtil.lastExecVersion nodes updates
credentials.xml jenkins.install.UpgradeWizard.state plugins userContent
fingerprints jenkins.model.JenkinsLocationConfiguration.xml queue.xml users
hudson.model.UpdateCenter.xml jenkins.telemetry.Correlator.xml queue.xml.bak workflow-libs
hudson.plugins.git.GitTool.xml jobs secret.key workspace
identity.key.enc logs secret.key.not-so-secret
jenkins.install.InstallUtil.installingPlugins nodeMonitors.xml secrets
五、启动tomcat,也就启动了jenkins
[root@k8s-node-2 opt]# app/apache-tomcat-8.0.27/bin/startup.sh
Using CATALINA_BASE: /opt/app/apache-tomcat-8.0.27
Using CATALINA_HOME: /opt/app/apache-tomcat-8.0.27
Using CATALINA_TMPDIR: /opt/app/apache-tomcat-8.0.27/temp
Using JRE_HOME: /usr
Using CLASSPATH: /opt/app/apache-tomcat-8.0.27/bin/bootstrap.jar:/opt/app/apache-tomcat-8.0.27/bin/tomcat-juli.jar
Tomcat started.
六、访问jenkins 10.0.0.13:8080 admin 123456

七、新建一个任务yinliao,确定
八、general里选参数化构建过程,定义version变量,方便升级失败回滚;
源码管理git,Repositories:码云url,添加:输入gitee用户名、密码
构建:执行shell,输入自动构建镜像的命令,然后保存
docker build -t yiliao:$version . #构建镜像
docker tag yiliao:v1 10.0.0.11:5000/yiliao:$version #打标签
docker push 10.0.0.11:5000/yiliao:$version #推送私有仓库
kubectl -s 10.0.0.11:8080 set image -n yiliao deployment yiliao yiliao=10.0.0.11:5000/yiliao:$version #更新k8s中打deployment镜像版本
九、点击构建 Build with Parameters,jenkins把码云上的代码拉到本地目录
[root@k8s-node-2 opt]# ls /root/.jenkins/workspace/yiliao/
about.html article.html css/ images/ product_detail.html
album.html comment.html Dockerfile index.html product.html
article_detail.html contact.html .git/ js/ README.md
十、创建namespace,一个项目一个namespace
[root@k8s-master opt]# kubectl create namespace yiliao
namespace "yiliao" created
十一、创建deployment资源
[root@k8s-master opt]# kubectl run -n yiliao yiliao --image=10.0.0.11:5000/yiliao:v1 --replicas=2
deployment "yiliao" created
十二、创建svc,暴露端口
十三、查看项目,已经在k8s中运行起来了
[root@k8s-master opt]# kubectl get all -n yiliao
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
deploy/yiliao 2 2 2 2 4m
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
svc/yiliao 10.254.146.161 <nodes> 80:44218/TCP 1m
NAME DESIRED CURRENT READY AGE
rs/yiliao-253796219 2 2 2 4m
NAME READY STATUS RESTARTS AGE
po/yiliao-253796219-rplt0 1/1 Running 0 4m
po/yiliao-253796219-w3tt0 1/1 Running 0 4m
[root@k8s-master opt]# kubectl expose -n yiliao deployment yiliao --port=80 --target-port=80 --type=NodePort
service "yiliao" exposed
十四、版本更新,输入版本信息,自动构建镜像

jenkins立即构建过程总结:
1.拉取代码
2.构建docker镜像
3.上传镜像到私有仓库
4.远程控制k8s更新deployment
十五、回滚shell命令
kubectl -s 10.0.0.11:8080 rollout undo -n yiliao deployment yiliao
指定版本信息,也可以完成回滚
kubectl -s 10.0.0.11:8080 set image -n yiliao deployment yiliao yiliao=10.0.0.11:5000/yiliao:$version
0 Comments