rancher jenkins 自动化发布

一、hostport

1、deploy.sh

#!/bin/sh
source /etc/profile

projectName=$1
namespace=$2
replicas=$3
image=$4
containerPort=$5
hostPort=$6

eval "cat <<EOF
$(< deploymentTemplate.yml)
EOF
"  > "$projectName"_dp.yml

eval "cat <<EOF
$(< serviceTemplate.yml)
EOF
"  > "$projectName"_ser.yml


result=$(rancher kubectl get deployment --namespace=$namespace | grep -w $projectName)
#echo "$result"
if [ -z "$result" ]; then
   rancher kubectl create -f "$projectName"_dp.yml
else 
   rancher kubectl replace -f "$projectName"_dp.yml
fi

result=$(rancher kubectl get service --namespace=$namespace | grep -w $projectName)
#echo "$result"
if [ -z "$result" ]; then
   rancher kubectl create -f "$projectName"_ser.yml
else
   rancher kubectl replace --force -f "$projectName"_ser.yml
fi
2、deploymentTemplate.yml

apiVersion: apps/v1beta2
kind: Deployment
metadata:
  labels:
    workload.user.cattle.io/workloadselector: deployment-${namespace}-${projectName}
  name: ${projectName}
  namespace: ${namespace}
spec:
  replicas: ${replicas}
  selector:
    matchLabels:
      workload.user.cattle.io/workloadselector: deployment-${namespace}-${projectName}
  template:
    metadata:
      annotations:
        field.cattle.io/ports: '[[{"containerPort":${containerPort},"dnsName":"${projectName}-hostport","hostPort":${hostPort},"kind":"HostPort","name":"${containerPort}tcp${hostPort}","protocol":"TCP","sourcePort":${hostPort}}]]'
      labels:
        workload.user.cattle.io/workloadselector: deployment-${namespace}-${projectName}
    spec:
      containers:
      - name: ${projectName}
        image: ${image}
        imagePullPolicy: Always
        ports:
        - containerPort: ${containerPort}
          hostPort: ${hostPort}
          name: ${containerPort}tcp${hostPort}
          protocol: TCP
3、serviceTemplate.yml

apiVersion: v1
kind: Service
metadata:
  annotations:
    field.cattle.io/targetWorkloadIds: '["deployment:${namespace}:${projectName}"]'
    workload.cattle.io/targetWorkloadIdNoop: "true"
    workload.cattle.io/workloadPortBased: "true"
  labels:
    workload.user.cattle.io/workloadselector: deployment-${namespace}-${projectName}
  name: ${projectName}
  namespace: ${namespace}
  #ownerReferences:
  #- apiVersion: apps/v1beta2
  #  controller: true
  #  kind: deployment
  #  name: ${projectName}
spec:
  ports:
  - port: ${containerPort}
    protocol: TCP
    targetPort: ${containerPort}
  selector:
    workload.user.cattle.io/workloadselector: deployment-${namespace}-${projectName}
  sessionAffinity: None
  type: ClusterIP
二、nodeport

1、deployNoteType.sh

#!/bin/sh
source /etc/profile

projectName=$1
namespace=$2
replicas=$3
image=$4
containerPort=$5
nodePort=$6

eval "cat <<EOF
$(< deploymentTemplateNotetype.yml)
EOF
"  > "$projectName"_dp.yml

eval "cat <<EOF
$(< serviceTemplateNotetype.yml)
EOF
"  > "$projectName"_ser.yml


result=$(rancher kubectl get deployment --namespace=$namespace | grep -w $projectName)
#echo "$result"
if [ -z "$result" ]; then
   rancher kubectl create -f "$projectName"_dp.yml
else 
   rancher kubectl replace -f "$projectName"_dp.yml
fi

result=$(rancher kubectl get service --namespace=$namespace | grep -w $projectName)
#echo "$result"
if [ -z "$result" ]; then
   rancher kubectl create -f "$projectName"_ser.yml
else
   rancher kubectl replace --force -f "$projectName"_ser.yml
fi
2、deploymentTemplateNotetype.yml
apiVersion: apps/v1beta2
kind: Deployment
metadata:
  labels:
    workload.user.cattle.io/workloadselector: deployment-${namespace}-${projectName}
  name: ${projectName}
  namespace: ${namespace}
spec:
  replicas: ${replicas}
  selector:
    matchLabels:
      workload.user.cattle.io/workloadselector: deployment-${namespace}-${projectName}
  template:
    metadata:
      annotations:
        field.cattle.io/ports: '[[{"containerPort":${containerPort},"dnsName":"${projectName}-noteport","kind":"NodePort","name":"${containerPort}tcp${nodePort}","protocol":"TCP","sourcePort":"${nodePort}"}]]'
      labels:
        workload.user.cattle.io/workloadselector: deployment-${namespace}-${projectName}
    spec:
      containers:
      - name: ${projectName}
        image: ${image}
        imagePullPolicy: Always
        ports:
        - containerPort: ${containerPort}
          name: ${containerPort}tcp${nodePort}
          protocol: TCP
  3、serviceTemplateNotetype.yml

apiVersion: v1
kind: Service
metadata:
  annotations:
    field.cattle.io/targetWorkloadIds: '["deployment:${namespace}:${projectName}"]'
    workload.cattle.io/targetWorkloadIdNoop: "true"
    workload.cattle.io/workloadPortBased: "true"
  labels:
    workload.user.cattle.io/workloadselector: deployment-${namespace}-${projectName}
  name: ${projectName}
  namespace: ${namespace}
  #ownerReferences:
  #- apiVersion: apps/v1beta2
  #  controller: true
  #  kind: deployment
  #  name: ${projectName}
spec:
  ports:
  - nodePort: ${nodePort}
    port: ${containerPort}
    protocol: TCP
    targetPort: ${containerPort}
  selector:
    workload.user.cattle.io/workloadselector: deployment-${namespace}-${projectName}
  sessionAffinity: None
  type: NodePort
三、

3、./deploy.sh zuul platform 3 192.166.33.10/test/zuul:1.0 8080 18080

 用法:

命令  服务名  命令空间  复本数量 镜像 容器端口 hostport或nodeport 

4、jenkins

git拉取、mvn编译打包、docker镜像推送、ranchercli 发布

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值