#在運(yùn)維主機(jī)操作:
1.準(zhǔn)備鏡像
~]# docker pull jenkins/jenkins:2.190.3
~]# docker images | grep jenkins
~]# docker tag 22b8b9a84dbe test-harbor.cedarhd.com/public/jenkins:v2.190.3
~]# docker push test-harbor.cedarhd.com/public/jenkins:v2.190.3
2.自定義Dockerfile
#官網(wǎng)拉取的鏡像需要做些自定義操作,才能在k8s集群中部署(運(yùn)維主機(jī)上運(yùn)行)
mkdir -p /data/dockerfile/jenkins
cd /data/dockerfile/jenkins
vim Dockerfile
FROM test-harbor.cedarhd.com/public/jenkins:v2.190.3
USER root
RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime &&\
echo 'Asia/Shanghai' >/etc/timezone
ADD id_rsa /root/.ssh/id_rsa
ADD config.json /root/.docker/config.json
ADD get-docker.sh /get-docker.sh
RUN echo "StrictHostKeyChecking no" >> /etc/ssh/ssh_config &&\
/get-docker.sh
#解釋?zhuān)?> - 設(shè)置容器用戶(hù)為root
> - 設(shè)置容器內(nèi)的時(shí)區(qū)
> - 將ssh私鑰加入(使用git拉代碼時(shí)要用到,配對(duì)的公鑰應(yīng)配置在gitlab中)
> - 加入了登錄自建harbor倉(cāng)庫(kù)的config文件
> - 修改了ssh客戶(hù)端的
> - 安裝一個(gè)docker的客戶(hù)端
> - 如果因?yàn)榫W(wǎng)絡(luò)原因構(gòu)建失敗,可以在最后“ /get-docker.sh --mirror Aliyun”
3.生成ssh密鑰對(duì)
jenkins]# ssh-keygen -t rsa -b 2048 -C "xxxxxxx@qq.com" -N "" -f /root/.ssh/id_rsa
Generating public/private rsa key pair.
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:bIajghsF/BqJouTeNvZXvQWvolAKWvhVSuZ3uVWoVXU 897307140@qq.com
The key's randomart image is:
+---[RSA 2048]----+
| ...E|
|. o .|
|.. o . o . |
|..+ + oo +.. |
|o=.+ +ooS+..o |
|=o* o.++..o. o |
|++...o .. + |
|.o.= .. . o |
|..o.o.... . |
+----[SHA256]-----+
enkins]# cp /root/.ssh/id_rsa .
4.準(zhǔn)備其它文件
jenkins]# cp /root/.docker/config.json .
jenkins]# curl -fsSL get.docker.com -o get-docker.sh
jenkins]# chmod +x get-docker.sh
jenkins]# ll
total 28
-rw------- 1 root root 160 Jan 28 23:41 config.json
-rw-r--r-- 1 root root 355 Jan 28 23:38 Dockerfile
-rwxr-xr-x 1 root root 13216 Jan 28 23:42 get-docker.sh
-rw------- 1 root root 1675 Jan 28 23:38 id_rsa
5、登陸harbor創(chuàng)建infra私有倉(cāng)庫(kù)
創(chuàng)建infra的project,access level 為Private
6、生成jenkins鏡像
jenkins]# docker build -t harbor.phc-dow.com/infra/jenkins:v2.190.3 .
jenkins]# docker push test-harbor.cedarhd.com/infra/jenkins:v2.190.3
7、準(zhǔn)備共享存儲(chǔ)
yum install nfs-utils -y
~]# vim /etc/exports
/data/nfs-volume 10.4.7.0/24(rw,no_root_squash)
###啟動(dòng)NFS服務(wù)
~]# mkdir -p /data/nfs-volume
~]# systemctl start nfs
~]# systemctl enable nfs
mkdir /data/k8s-yaml/jenkins && mkdir -p /data/nfs-volume/jenkins_home && cd /data/k8s-yaml/jenkins
~]# vi dp.yaml #用于創(chuàng)建配置pod控制器與pod資源
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
name: jenkins
namespace: infra
labels:
name: jenkins
spec:
replicas: 1
selector:
matchLabels:
name: jenkins
template:
metadata:
labels:
app: jenkins
name: jenkins
spec:
volumes:
- name: data
nfs:
server: test-operator.cedarhd.com
path: /data/nfs-volume/jenkins_home
- name: docker
hostPath:
path: /run/docker.sock
type: ''
containers:
- name: jenkins
image: test-harbor.cedarhd.com/infra/jenkins:v2.190.3
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8080
protocol: TCP
env:
- name: JAVA_OPTS
value: -Xmx512m -Xms512m
volumeMounts:
- name: data
mountPath: /var/jenkins_home
- name: docker
mountPath: /run/docker.sock
imagePullSecrets:
- name: harbor
securityContext:
runAsUser: 0
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 1
maxSurge: 1
revisionHistoryLimit: 7
progressDeadlineSeconds: 600
-----------------------------------------------------------------------------------------------
~]# vim service.yaml #用于創(chuàng)建cluster ip與端口映射
kind: Service
apiVersion: v1
metadata:
name: jenkins
namespace: infra
spec:
ports:
- protocol: TCP
port: 80
targetPort: 8080
selector:
app: jenkins
jenkins]# cat ingress.yaml #用于創(chuàng)建ingress轉(zhuǎn)發(fā)規(guī)則
kind: Ingress
apiVersion: extensions/v1beta1
metadata:
name: jenkins
namespace: infra
spec:
rules:
- host: test-jenkins.cedarhd.com
http:
paths:
- path: /
backend:
serviceName: jenkins
servicePort: 80
-----------------------------------------------------------------------------------------------
kubectl apply -f http://k8s-yaml.cedarhd.com/jenkins/dp.yaml
kubectl apply -f http://k8s-yaml.cedarhd.com/jenkins/service.yaml
kubectl apply -f http://k8s-yaml.cedarhd.com/jenkins/ingress.yaml
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)建站m.rwnh.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性?xún)r(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專(zhuān)為企業(yè)上云打造定制,能夠滿(mǎn)足用戶(hù)豐富、多元化的應(yīng)用場(chǎng)景需求。
“只有客戶(hù)發(fā)展了,才有我們的生存與發(fā)展!”這是創(chuàng)新互聯(lián)的服務(wù)宗旨!把網(wǎng)站當(dāng)作互聯(lián)網(wǎng)產(chǎn)品,產(chǎn)品思維更注重全局思維、需求分析和迭代思維,在網(wǎng)站建設(shè)中就是為了建設(shè)一個(gè)不僅審美在線,而且實(shí)用性極高的網(wǎng)站。創(chuàng)新互聯(lián)對(duì)網(wǎng)站設(shè)計(jì)制作、做網(wǎng)站、網(wǎng)站制作、網(wǎng)站開(kāi)發(fā)、網(wǎng)頁(yè)設(shè)計(jì)、網(wǎng)站優(yōu)化、網(wǎng)絡(luò)推廣、探索永無(wú)止境。
網(wǎng)站題目:Kubernetes安裝配置Jenkins-創(chuàng)新互聯(lián)
文章路徑:http://m.rwnh.cn/article28/djepjp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供企業(yè)網(wǎng)站制作、App設(shè)計(jì)、域名注冊(cè)、全網(wǎng)營(yíng)銷(xiāo)推廣、電子商務(wù)、營(yíng)銷(xiāo)型網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容