jenkins构建php
2021-04-18 本文已影响0人
慕知
一,准备环境
[root@\ k8s-m-01~]# vim jenkins_php.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:
containers:
- name: php
image: alvinos/php:discuz-v2
volumeMounts:
- mountPath: /usr/share/nginx/html
name: data
- name: nginx
image: alvinos/nginx:discuz-v1
volumeMounts:
- mountPath: /usr/share/nginx/html
name: data
volumes:
- name: data
nfs:
path: /nfs/v6
server: 172.16.1.31
---
kind: Service
apiVersion: v1
metadata:
name: jenkins-nginx-php-svc
spec:
ports:
- port: 80
targetPort: 80
selector:
app: jenkins-nginx-php
type: NodePort
[root@\ k8s-m-01~]# kubectl apply -f jenkins_php.yaml
deployment.apps/jenkins-nginx-php created
service/jenkins-nginx-php-svc created
[root@\ k8s-m-01~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
jenkins-nginx-php-587b6899fb-xndd8 2/2 Running 0 6s
[root@\ k8s-m-01~]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
访问如下

添加文件测试
[root@\ k8s-m-01/nfs/v6]# echo "<?php phpinfo();" > index.php
这时访问可能还是403.增加目录权限如下
[root@\ k8s-m-01/nfs/v6]# cd ..
[root@\ k8s-m-01/nfs]# chmod 777 -R v6

二,部署PHP
1,jenkins服务器对目标服务器做免密
[root@\ jenkins~]# ssh-copy-id -i .ssh/id_rsa.pub root@192.168.15.31
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: ".ssh/id_rsa.pub"
The authenticity of host '192.168.15.31 (192.168.15.31)' can't be established.
ECDSA key fingerprint is SHA256:PEnseRsQ3H01Fz7upthyVuJfTYF/AKSpERCAxx1052M.
ECDSA key fingerprint is MD5:e7:ba:23:9f:6c:2b:77:12:7b:68:a8:5f:bc:eb:c0:01.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.15.31's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@192.168.15.31'"
and check to make sure that only the key(s) you wanted were added.
[root@\ jenkins~]# ssh root@192.168.15.31
Last login: Sun Apr 18 18:24:36 2021 from 192.168.15.1
[root@\ k8s-m-01~]# exit
logout
Connection to 192.168.15.31 closed.
2,jenkins增加server








[root@\ k8s-m-01/nfs/v6]# ll
total 16
-rw-r--r--. 1 root root 14 Apr 18 20:46 index.html
-rwxrwxrwx. 1 root root 17 Apr 18 19:52 index.php
-rw-r--r--. 1 root root 17 Apr 18 20:46 phpinfo.php
drwxr-xr-x. 4 root root 72 Apr 18 20:33 springboot
-rw-r--r--. 1 root root 29 Apr 18 20:46 test.php

PS:
如果更新代码,新创建一个标签,再次直接构建即可