Jenkins容器化、发送邮件

Jenkins容器化、发送邮件

1、容器化简介

1.为什么有容器化	
	因为jenkins可能要部署多个环境 ,用到的东西不一样
2.容器化有什么作用
	解决了环境冲突,只能用流水线
	

2、使用Jenkins连接k8s

第一步:创建admin-csr.json
cat > admin-csr.json << EOF
{
    "CN":"admin",
    "key":{
        "algo":"rsa",
        "size":2048
    },
    "names":[
        {
            "C":"CN",
            "L":"BeiJing",
            "ST":"BeiJing",
            "O":"system:masters",
            "OU":"System"
        }
    ]
}
EOF

第二步:创建证书和私钥
	
	1、kubeadm安装
		cfssl gencert -ca=/etc/kubernetes/pki/ca.crt -ca-key=/etc/kubernetes/pki/ca.key --profile=kubernetes admin-csr.json | cfssljson -bare admin
	2、二进制安装
		cfssl gencert -ca=/etc/kubernetes/ssl/ca.pem -ca-key=/etc/kubernetes/ssl/ca-key.pem --profile=kubernetes admin-csr.json | cfssljson -bare admin
		
第三步:配置证书
	openssl pkcs12 -export -out ./jenkins-admin.pfx -inkey ./admin-key.pem -in ./admin.pem -passout pass:123456


3、Jenkins调用k8s

1、容器化部署Django
	
	1、基础环境
---
kind: Deployment
apiVersion: apps/v1
metadata:
  name: django
spec:
  selector:
    matchLabels:
      app: django
  template:
    metadata:
      labels:
        app: django
    spec:
      containers:
        - name: django
          image: nginx
---
kind: Service
apiVersion: v1
metadata:
  name: django
spec:
  ports:
    - port: 80
      targetPort: 80
  selector:
    app: django
---
kind: Ingress
apiVersion: extensions/v1beta1
metadata:
  name: django
spec:
  rules:
    - host: www.django.com
      http:
        paths:
          - backend:
              serviceName: django
              servicePort: 80
            path: /

	2、下载代码

	3、打包镜像
	4、上传镜像
	5、部署到k8s
	
	[root@k8s-master-01 jenkins]# kubectl create secret generic  kubeconfig --from-file=/etc/kubernetes/cfg/admin.kubeconfig 
secret/kubeconfig created
	6、发邮件通知

4、发送邮件

下载Email插件:Email Extension

posted @ 2022-01-15 16:02  迪迦张  阅读(44)  评论(0编辑  收藏  举报