jenkins on k8s;插件配置;简单CICD持续部署测试
1、k8s安装jenkins参考:https://blog.csdn.net/qq_38942551/article/details/107769120jenkins可以在k8s集群中安装,方便自动管理;也可以单独k8s外部署安装,本文是安装在k8s中1、创建namespacekubectl create namespace jenkins查看:kubectl get namespace2、创建j
1、k8s安装jenkins(jenkins on k8s)
参考:https://blog.csdn.net/qq_38942551/article/details/107769120
jenkins可以在k8s集群中安装,方便自动管理;也可以单独k8s外部署安装,本文是安装在k8s中
1、创建namespace
kubectl create namespace jenkins
查看:kubectl get namespace
2、创建jenkins.yaml文件
deployment和service集成在一个yaml了
jenkins.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: jenkins-deployment
spec:
replicas: 1
selector:
matchLabels:
app: jenkins
template:
metadata:
labels:
app: jenkins
spec:
containers:
- name: jenkins
image: jenkinsci/blueocean:latest
ports:
- containerPort: 8080
volumeMounts:
- name: jenkins-home
mountPath: /var/jenkins_home
volumes:
- name: jenkins-home
emptyDir: {}
---
apiVersion: v1
kind: Service
metadata:
name: jenkins
spec:
type: NodePort
ports:
- port: 8080
targetPort: 8080
nodePort: 30000
selector:
app: jenkins
3、k8s运行部署jenkins.yaml,拉取启动jenkinsfuw
kubectl apply -f jenkins.yaml -n jenkins
(-n jenkins 指的就是namespace)
查看部署的信息:
查看pod:kubectl get pods -n jenkins
查看deployment:kubectl get deployment -n jenkins
产看service:kubectl get service -n jenkins
(kubectl命令参考:https://www.jianshu.com/p/8710a3a0aadd)
4、最终效果
## ip映射(把本地的port 映射到k8s服务的port)
kubectl port-forward -n jenkins service/jenkins 30001:8080
5、进入容器获取jenkins初始登录密码
kubectl exec -n jenkins -it jenki***podname*-g898t bash
进入后:cat /var/jenkins_home/secrets/initialAdminPassword
6、打开web查看
http://localhost:30001/
*windows安装jenkins
下载:
http://mirrors.jenkins-ci.org/ 镜像下载安装
http://mirrors.jenkins-ci.org/windows-stable/ 下载的zip文件包
启动和关闭jenkins
管理员cmd下:
net start jenkins
net stop jenkins
http://localhost:8080
密码在安装目录jenkins.err 文件里也可以看到
2、jenkins中安装k8s插件配置
1、插件中心安装kubernets插件后重启jenkins生效
2、配置(系统配置里最后添加cloud)
a、ip地址需要进入k8s内环境ipconfig查看
b、因为namespace空间报错(User "system:serviceaccount:default:default" ),需要查询注册个到jenkins的namespace;运行下列:
kubectl create clusterrolebinding spark-role1 --clusterrole=edit --serviceaccount=default:spark --namespace=jenkins
3、简单CICD持续部署测试
参考:https://www.cnblogs.com/coolops/p/13129955.html
1、创建个自由项目
#执行的shell
echo "hello"
pwd
workspace空间查看需要进入jenkins 容器里
kubectl get pod -n jenkins 查看容器id
kubectl exec -it -n jenkinsjen***8dc768-kr7vf bash
2、构建流水线项目
pipeline基础语法参考:https://www.jianshu.com/p/f1167e8850cd
https://www.jenkins.io/zh/doc/pipeline/tour/running-multiple-steps/
可以通过jenkins blue ocean查看流水线:
也可以查看pod看运行情况
kubectl get pod -n jenkins
更多推荐
所有评论(0)