In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
The topic of this chapter is Jenkins automating docker images and deploying them to the k8s cluster. We will talk about Jenkins publishing to the k8s cluster with one click later.
Installing jenkins requires tomcat to run the application
1. Clean up all default resources and resources under other namespaces
[root@master ~]# kubectl get all --all-namespaces
kubectl delete svc --all;kubectl delete pod --all
2. Download gitlab installation package
On node2, do the following
wget xxx
Install: yum localinstall xxx
Configuration: vim /etc/gitlab/gitlab.rb, modify the following two lines
external_url 'http://192.168.187.102'prometheus_monitoring['enable'] = flase
Restart:
3. Create repository on gitlab and upload code
git add .
git commit -m 'first update'
git push -u origin master
4. install Jenkins
On node1, do the following
Install JDK, install tomcat, install jenkins
[root@node1 ~]# rpm -ivh jdk-12.0.2_linux-x64_bin.rpm
warning: jdk-12.0.2_linux-x64_bin.rpm: Header V3 RSA/SHA256 Signature, key ID ec551f03: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:jdk-12.0.2-2000:12.0.2-ga ################################# [100%]
[root@node1 ~]# java --version
java 12.0.2 2019-07-16
Java(TM) SE Runtime Environment (build 12.0.2+10)
Java HotSpot(TM) 64-Bit Server VM (build 12.0.2+10, mixed mode, sharing)
Extract tomcat package to specified folder
tar xf apache-tomcat-8.5.45.tar.gz -C /app
Copy the jenkins.war package to tomcat's webapps directory and start tomcat. Since our installation method is based on tomcat, starting tomcat will automatically start jenkins.
[root@node1 ~]# cp jenkins.war /app/apache-tomcat-8.5.45/webapps/
[root@node1 ~]# ls
! anaconda-ks.cfg apache-tomcat-8.5.45.tar.gz jdk-12.0.2_linux-x64_bin.rpm jenkins.war original-ks.cfg
[root@node1 webapps]# /app/apache-tomcat-8.5.45/bin/startup.sh
[root@node1 webapps]# netstat -lntup | grep 8080
tcp6 0 0 :::8080 :::* LISTEN 81725/java
To start, log in to http://192.168.187.101:8080/jenkins on your browser and enter the original password. Copy the password in the following file to here.
[root@node1 secrets]# vim initialAdminPassword
[root@node1 secrets]# pwd
/root/.jenkins/secrets
Next, you will see an interface that allows you to select the startup module and skip to the next step.
Pulling code from gitlab on a machine with jenkins installed, normally pulls successfully
Here is a screenshot of Jenkins pulling code successfully
5. Jenkins automates docker image building
In production, when we click build now on jenkins, a docker image is immediately packaged.
This is our ultimate goal:
A common practice for many of us is to edit a dockerfile while committing code on gitlab. When you click build now on jenkins, jenkins automatically executes docker build to complete the process of building a docker image because of the existence of this dockerfile
a. First create dockerfile file on node2, and edit a file without packaging this file when executing
vi dockerfile
FROM 192.168.187.100:5000/nginx:1.13
ADD . /usr/share/nginx/html #Upload code to this directory
b. Copy docker build, docker push commands from jenkins to the configuration-build-interface, which will be executed when you click build now
docker build
docker push 192.168.187.100:5000/
After execution, you can check docker images to see if the image will be in the mirror pool of the private repository
6. Optimize some configurations in the build
First of all, if you build many times and you want to save the historical version, you don't want the old version to be overwritten, then you need to set the version variable.
In Configure-Build, change the version number to a variable so that it changes with each build
Second, if the code has not changed and we do not want to perform the action of building again, then we need to do a check to check whether the code has been updated and whether there is a new build; here we use the commit id as the basis for judging. If the commit id is the same as last time, we will not build again. If it is inconsistent, we will execute the build command.
7.k8s Cluster Deployment Project
7.1. Create Project Resources
a. Create a deployment with the bird image uploaded to the local private repository as the source.
kubectl run
b. Create an svc that provides external access to the birdie app.
kubectl expose
7.2. Manual implementation of docker upgrade and rollback in k8s
kubectl set image deploy
kubectl rollout undo deploy
7.3. Using jenkins to upgrade and rollback docker in k8s
Integrate the above upgrade and rollback operations into the configuration-build configuration, and let jenkins implement the docker upgrade and rollback;
We can do an experiment by creating an html file in gitlab and building it and uploading the code to a private repository.
Then through jenkins immediate build function to achieve k8s docker resources one-click update, deployment or release.
kubectl -s 192.168.187.100:8080 set image deploy xiaoniao:
Question:
1. After the jenkins installation is completed, the initialization startup has been very slow, showing that the load is in progress, and the modified configuration does not take effect.
2.jenkins one-click build to complete the update and release of docker resources in k8s, very awesome, hope to have the opportunity to understand its application status in the production environment
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
Https://www.cnblogs.com/LinHuChongChongChong/
© 2024 shulou.com SLNews company. All rights reserved.