Jenkins部署nacos到k8s集群
nginx-ingress.yamlapiVersion: v1kind: Namespacemetadata:name: ingress-nginx---kind: ConfigMapapiVersion: v1metadata:name: nginx-configurationnamespace: ingress-nginxlabels:app.kubernetes.io/name: ingr
·
部署nacos
vcloud-nacos.yaml
apiVersion: v1
kind: Service
metadata:
name: $APP_NAME-sit
namespace: sit
spec:
selector:
appname: $APP_NAME
clusterIP: None
ports:
- port: 8848
targetPort: 8848
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: $APP_NAME
namespace: sit
spec:
replicas: 1
selector:
matchLabels:
appname: $APP_NAME
template:
metadata:
labels:
appname: $APP_NAME
annotations:
prometheus.io/scrape: true
prometheus.io/path: "/nacos/actuator/prometheus"
prometheus.io/port: 8848
spec:
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- podAffinityTerm:
labelSelector:
matchExpressions:
- key: appname
operator: In
values:
- $APP_NAME
topologyKey: "kubernetes.io/hostname"
weight: 50
containers:
- name: $APP_NAME
image: $IMAGE_NAME
---
apiVersion: v1
kind: Service
metadata:
name: vcloud-nacos-web
namespace: sit
spec:
selector:
appname: $APP_NAME
type: ClusterIP
ports:
- port: 8848
targetPort: 8848
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: vcloud-nacos-web
annotations:
kubernetes.io/ingress.class: "traefik"
namespace: sit
spec:
rules:
- host: nacos.wuxingge.com
http:
paths:
- path:
backend:
serviceName: vcloud-nacos-web
servicePort: 8848
Jenkinsfile
def registry = "harbor.wuxingge.com"
def project = "uat"
def app_name = "vcloud-nacos-api"
def jenkins_slave_image = "${registry}/uat/jenkins-slave-maven-3.6.3:v1"
def image_name = "${registry}/${project}/${app_name}:${BUILD_NUMBER}"
def git_address = "http://10.10.110.212/VCloud-framework/vcloud-nacos.git"
def docker_registry_auth = "my_harbor"
def git_auth = "my_gitlab_auth"
def k8s_auth = "9287e264-2fc3-42f7-9885-8258875fb6ae"
def k8s_cloud_name = "kubernetes"
def jar_name = 'vcloud-nacos-api.jar'
def label_name = "jenkins-slave-${app_name}-${project}"
def mysql = '10.10.111.170'
podTemplate(label: "$label_name", cloud: "$k8s_cloud_name", containers: [
containerTemplate(
name: 'jnlp',
image: "${jenkins_slave_image}",
runAsGroup: '0',
runAsUser: '0',
privileged: true
),
],
volumes: [
hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock'),
hostPathVolume(mountPath: '/usr/bin/docker', hostPath: '/usr/bin/docker'),
hostPathVolume(mountPath: '/root/.m2', hostPath: '/root/.m2'),
hostPathVolume(mountPath: '/root/dockerfile-yaml', hostPath: '/dockerfile_yaml')
],
)
{
node("$label_name"){
stage('拉取代码'){
git branch: "$Branch",credentialsId: "$git_auth", url: "$git_address"
}
stage('构建镜像'){
//harbor登录
withCredentials([usernamePassword(credentialsId: "${docker_registry_auth}", passwordVariable: 'password', usernameVariable: 'username')]) {
sh """
cp /root/dockerfile-yaml/vcloud-nacos-api/Dockerfile ./
sed -i 's#192.168.47.16#${mysql}#g' conf/application.properties
docker build -t ${image_name} ./
docker login -u ${username} -p '${password}' '${registry}'
docker push ${image_name}
"""
}
}
stage('部署到K8S平台'){
sh """
cp /root/dockerfile-yaml/vcloud-nacos-api/vcloud-nacos.yaml ./${app_name}.yaml
sed -i 's#\$IMAGE_NAME#${image_name}#g' ${app_name}.yaml
sed -i 's#\$APP_NAME#${app_name}#g' ${app_name}.yaml
"""
kubernetesDeploy configs: "${app_name}.yaml", kubeconfigId: "${k8s_auth}"
}
}
}
Dockerfile
FROM harbor.wuxingge.com/sit/java-8-jdk-skywalking-agent:v1
LABEL maintanier="wuxingge<wuxingge@wuxinggge.com>"
COPY ./ /opt/nacos/
ENTRYPOINT ["java","-Xms512m","-Xmx512m","-Xmn256m","-Dnacos.standalone=true","-Djava.ext.dirs=/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/ext:/usr/lib/jvm/java-1.8.0-openjdk-amd64/lib/ext","-Xloggc:/opt/nacos/logs/nacos_gc.log","-verbose:gc","-XX:+PrintGCDetails","-XX:+PrintGCDateStamps","-XX:+PrintGCTimeStamps","-XX:+UseGCLogFileRotation","-XX:NumberOfGCLogFiles=10","-XX:GCLogFileSize=100M","-Dloader.path=/opt/nacos/plugins/health,/opt/nacos/plugins/cmdb,/opt/nacos/plugins/mysql","-Dnacos.home=/opt/nacos","-jar","/opt/nacos/target/nacos-server.jar", "--spring.config.location=classpath:/,classpath:/config/,file:./,file:./config/,file:/opt/nacos/conf/","--logging.config=/opt/nacos/conf/nacos-logback.xml","--server.max-http-header-size=524288"]
访问
http://nacos.wuxingge.com/nacos/
附
nacos启动命令
java -server -Xms2g -Xmx2g -Xmn1g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m -XX:-OmitStackTraceInFastThrow -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/opt/nacos/logs/java_heapdump.hprof -XX:-UseLargePages -Djava.ext.dirs=/usr/local/jdk/jre/lib/ext:/usr/local/jdk/lib/ext -Xloggc:/opt/nacos/logs/nacos_gc.log -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=100M -Dloader.path=/opt/nacos/plugins/health,/opt/nacos/plugins/cmdb,/opt/nacos/plugins/mysql -Dnacos.home=/opt/nacos -jar /opt/nacos/target/nacos-server.jar --spring.config.location=classpath:/,classpath:/config/,file:./,file:./config/,file:/opt/nacos/conf/ --logging.config=/opt/nacos/conf/nacos-logback.xml --server.max-http-header-size=524288 nacos.nacos
Jenkins连接k8s集群
https://blog.csdn.net/wuxingge/article/details/119514607
k8s凭据
Kubernetes Continuous Deploy插件
/root/.kube/config
更多推荐
已为社区贡献33条内容
所有评论(0)