#1.在k8s集群的主节点上编写配置清单 [root@gdx1 ~]# vim yaml/jenkins-php-nginx.yaml kind: Deployment apiVersion: apps/v1 metadata: name: jenkins-nginx-php spec: selector: matchLabels: app: jenkins-nginx-php template: metadata: labels: app: jenkins-nginx-php spec: nodeName: gdx1 #指定部署在主节点上 containers: - name: php image: elaina0808/lnmp-php:v6 volumeMounts: - mountPath: /usr/share/nginx/html name: data - name: nginx image: elaina0808/lnmp-nginx:v9 volumeMounts: - mountPath: /usr/share/nginx/html name: data volumes: #使用nfs服务将容器的/usr/share/nginx/html挂载到主节点的/vfs/v7下方 - name: data nfs: path: /nfs/v7 server: 172.16.1.11 --- kind: Service apiVersion: v1 metadata: name: jenkins-nginx-php-svc spec: ports: - port: 80 targetPort: 80 selector: app: jenkins-nginx-php type: NodePort #2.部署配置清单 [root@gdx1 ~]# kubectl apply -f yaml/jenkins-php-nginx.yaml deployment.apps/jenkins-nginx-php created service/jenkins-nginx-php-svc created [root@gdx1 ~]# kubectl get pods NAME READY STATUS RESTARTS AGE jenkins-nginx-php-85bfb855f7-chpxl 2/2 Running 0 2m47s [root@gdx1 ~]# kubectl get svc NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE jenkins-nginx-php-svc NodePort 10.104.25.76 <none> 80:30457/TCP [root@gdx1 ~]# echo"<? phpinfo();" > /nfs/v7/index.php #手动添加访问的文件 注:浏览器访问192.168.12.11:30457出现php官网页面说明配置清单及环境无问题(如下图) 注:如果访问报错403的话,,需要修改权限到777 注:正经访问流程:浏览器通过IP+端口请求/nfs/v7下方文件,因为此路径与容器内/usr/share/nginx/html挂载,等同于访问/usr/share/nginx/html目录下文件。
#1.生成密钥对 [root@jenkins ~]# ssh-keygen -t rsa #2.将公钥推送到目标服务器(master) [root@jenkins ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.12.11
#1.下载代码管理工具git [root@gdx1 ~]# yum install git -y #2.克隆远程仓库到本地 [root@gdx1 ~]# git clone http://192.168.12.40/technology-department/jenkins-php.git 正克隆到 'jenkins-php'... Username for 'http://192.168.12.40': root Password for 'http://root@192.168.12.40': warning: 您似乎克隆了一个空版本库。 #3.将源代码文件移动到克隆仓库内 [root@gdx1 ~]# cd jenkins-php/ [root@gdx1 jenkins-php]# mv /root/data/index.php . [root@gdx1 jenkins-php]# mv /root/data/jenkins-php-nginx.yaml . [root@gdx1 jenkins-php]# ll 总用量 8 -rwxr-xr-x 1 root root 17 4月 6 17:31 index.php -rw-r--r-- 1 root root 864 4月 18 07:44 jenkins-php-nginx.yaml #4.设置用户名和邮箱 [root@gdx1 jenkins-php]# git config --global user.name "elaina_fang" [root@gdx1 jenkins-php]# git config --global user.email "admin@example.com" [root@gdx1 jenkins-php]# git config --get user.name elaina_fang [root@gdx1 jenkins-php]# git config --get user.email admin@example.com #5.将源码文件提交到暂存区 [root@gdx1 jenkins-php]# git add index.php [root@gdx1 jenkins-php]# git add jenkins-php-nginx.yaml [root@gdx1 jenkins-php]# git status # 位于分支 master # # 初始提交 # # 要提交的变更: # (使用 "git rm --cached <file>..." 撤出暂存区) # # 新文件: index.php # 新文件: jenkins-php-nginx.yaml # #6.将源码文件提交到缓存区 [root@gdx1 jenkins-php]# git commit -m "init" . [master(根提交) 2f75aff] init 2 files changed, 45 insertions(+) create mode 100755 index.php create mode 100644 jenkins-php-nginx.yaml #7.推送到远程仓库 [root@gdx1 jenkins-php]# git push -u origin master Username for 'http://192.168.12.40': root Password for 'http://root@192.168.12.40': Counting objects: 4, done. Delta compression using up to 2 threads. Compressing objects: 100% (3/3), done. Writing objects: 100% (4/4), 598 bytes | 0 bytes/s, done. Total 4 (delta 0), reused 0 (delta 0) To http://192.168.12.40/technology-department/jenkins-php.git * [new branch] master -> master 分支 master 设置为跟踪来自 origin 的远程分支 master。
选择不同分支进行构建
1)在gitlab上创建不同版本标签
2)在Jenkins上配置构建内容
选择不同标签进行构建