kubectl create ns devops
# 查看是否有storageclass
kubectl get sc
# 如果已经有sc,
# 修改pvc.yaml中的storageClassName
# 默认写的是nas-storage
kubectl apply -f pvc.yaml -n devops
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: jenkins
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: jenkins
subjects:
- kind: ServiceAccount
name: jenkins
namespace: devops
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: jenkins-ingress
spec:
ingressClassName: nginx
rules:
- host: jenkins.sxkj.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: jenkins
port:
number: 30080
kubectl apply -f deploy.yaml -n devops
管理插件中下载插件
节点管理 -> Configure Cloud
def label = "slave-${UUID.randomUUID().toString()}"
podTemplate(cloud: 'kubernetes', namespace:'devops',label: label, serviceAccount: 'jenkins',containers: [
containerTemplate(name: 'docker', image: 'docker:latest', command: 'cat', ttyEnabled: true),
containerTemplate(name: 'kubectl', image: 'cnych/kubectl', command: 'cat', ttyEnabled: true)
],volumes: [
hostPathVolume(mountPath: '/home/jenkins/.kube', hostPath: '/root/.kube'),
hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock'),
hostPathVolume(mountPath: '/etc/docker/daemon.json', hostPath: '/etc/docker/daemon.json')
], yaml: """
spec:
nodeSelector:
kubernetes.io/hostname: h249
hostalias:
- ip: 192.168.199.31
hostnames:
- "SXKJ"
"""
) {
node(label) {
stage('构建 Docker 镜像') {
git url: ' http://gogs.soaringnova.com/sxwl_DL/meta_be.git', branch: 'master'
container('docker') {
echo "构建 Docker 镜像阶段"
retry(2) { sh "docker build -t SXKJ:32775/meta-app:latest --output type=docker ." }
echo "build success"
}
}
stage('Docker Push 镜像') {
container('docker') {
retry(2) { sh "docker push SXKJ:32775/meta-app:latest" }
echo "Push success"
}
}
stage('运行 Kubectl') {
container('kubectl') {
echo "重启 pod"
sh "kubectl rollout restart deployments/app-be -n meta-demo"
}
}
}
}