k8s的部署脚本是什么(k8s,开发技术)

时间:2024-05-03 19:36:03 作者 : 石家庄SEO 分类 : 开发技术
  • TAG :

浅谈docker

docker可以类比为jvm,jvm也是虚拟机,然后docker的image可以类比为jar包,jar运行在jvm里面,image当然运行在docker容器里,然后jar包是通过maven 的pom.xml定义构建的产物,那docker也有一个Dockerfile来定义打包的镜像。在没有容器化之前,我们开发提供的最终产物是jar,容器化之后我们需要提供docker的镜像,docker的镜像会包含我们的jar,然后提供一个稳定的可移植的运行环境。下面是最简单的一个docker镜像构建:

k8s的部署脚本是什么

通过 docker build -t kl/sales . 就可以构建一个可运行的镜像

浅谈k8s的部署脚本

其实k8s的脚本没什么可说的,本身k8s的概念非常之多,具体可参考官方的文档,下面贴出我们的部署文件

apiVersion:extensions/v1beta1kind:Deploymentmetadata:name:sales-appnamespace:#namespacespec:replicas:2minReadySeconds:130#从容器启动到应用正常提供服务strategy:#k8s更新策略type:RollingUpdate#滚动更新rollingUpdate:maxSurge:2#更新时允许最大激增的容器数,默认replicas的1/4向上取整maxUnavailable:1#更新时允许最大unavailable容器数,默认replicas的1/4向下取整template:metadata:labels:app:sales-appspec:imagePullSecrets:#镜像拉取秘钥-name:xx-xx-xxcontainers:-name:salesimage:xxx-vpc.cn-xx.aliyuncs.com/keking/sales:#TagimagePullPolicy:Alwaysenv:-name:runShellvalue:#runShellports:-containerPort:6002name:webprotocol:TCPresources:limits:cpu:600mmemory:4Girequests:cpu:300mmemory:100MilivenessProbe:#检查是否存活httpGet:path:/healthport:6002initialDelaySeconds:240#首次检查在多少时间后periodSeconds:180#检查周期timeoutSeconds:3#超时时间failureThreshold:3#失败的阈值,连续三次readinessProbe:#检查是否成功启动httpGet:path:/healthport:6002initialDelaySeconds:140#首次检查在多少时间后periodSeconds:300#检查周期timeoutSeconds:3#超时时间---apiVersion:v1kind:Servicemetadata:name:sales-appnamespace:#namespacelabels:app:sales-appspec:selector:app:sales-appports:-name:webport:80targetPort:6002nodePort:31942type:NodePort

最后聊聊jenkins pipeline

和一般的jenkins pipeline定义一样,容器化后就多了两个步骤,一个是在jar生成后,根据前面的讲的Dockerfile文件构建docker的镜像,这个要求jenkins所在主机必须有docker的环境。第二个步骤是发送k8s的部署脚本到k8s容器,这个是通过jenkins kuberneetes插件来完成的,详见下面的jenkins脚本

podTemplate(label:'jnlp-slave',cloud:'kubernetes',containers:[containerTemplate(name:'jnlp',image:'xx-vpc.cn-xx.aliyuncs.com/keking/jenkins-slave:latest',alwaysPullImage:true),],volumes:[hostPathVolume(mountPath:'/var/run/docker.sock',hostPath:'/var/run/docker.sock'),hostPathVolume(mountPath:'/usr/bin/docker',hostPath:'/usr/bin/docker'),hostPathVolume(mountPath:'/usr/local/jdk',hostPath:'/usr/local/jdk'),hostPathVolume(mountPath:'/usr/local/maven',hostPath:'/usr/local/maven'),],imagePullSecrets:['registry-pull-secret'],){node("jnlp-slave"){stage('GitCheckout'){checkout([$class:'GitSCM',branches:[[name:"*/${branch}"]],doGenerateSubmoduleConfigurations:false,extensions:[],submoduleCfg:[],userRemoteConfigs:[[credentialsId:'xx',url:'http://xx.xx.xx/xx/yudian-salesplatform-boot.git']]])}stage('MavenBuild'){script{if('true'=="${build}"){sh"mvncleaninstall-U-P${profile}-Dmaven.test.skip=true"}else{echo"跳过mavenbuild"}}}stage('DockerBuild'){script{if('true'=="${build}"){sh'''dockerlogin-uit_sh@keking-group-px#xxx-vpc.cn-xx.aliyuncs.comdockerbuild-txx-vpc.cn-xx.aliyuncs.com/keking/sales:${Tag}.dockerpushxx-vpc.cn-xx.aliyuncs.com/keking/sales:${Tag}'''}else{echo"跳过dockerbuild"}}}stage('DeploytoK8s'){script{if('true'=="${deploy}"){if('prod'=="${profile}"){sh'''sed-i"s/#namespace/prod/g"deploy.yamlsed-i"s%#runShell%java-Xmx2G-Xms2G-Xmn960M-XX:+HeapDumpOnOutOfMemoryError-XX:HeapDumpPath=/tmp/dump.log-Xloggc:/tmp/gc.log-verbose:gc-XX:+PrintGCDateStamps-XX:+PrintGCDetails-XX:MaxMetaspaceSize=128m-XX:MetaspaceSize=128m-jar-Ddev_meta=http://conf.x.ops:8801/-Denv=DEV-Didc=prodapp.jar%g"deploy.yaml'''}if('uat'=="${profile}"){sh'''sed-i"s/#namespace/uat/g"deploy.yamlsed-i"s%#runShell%java-Xmx1536M-Xms1536M-Xmn960M-XX:+HeapDumpOnOutOfMemoryError-XX:HeapDumpPath=/tmp/dump.log-Xloggc:/tmp/gc.log-verbose:gc-XX:+PrintGCDateStamps-XX:+PrintGCDetails-XX:MaxMetaspaceSize=128m-XX:MetaspaceSize=128m-jar-Ddev_meta=http://conf.keking.ops:8801/-Denv=DEV-Didc=sales_dockerapp.jar%g"deploy.yaml'''}sh'''sed-i"s/#Tag/${Tag}/g"deploy.yaml'''kubernetesDeployconfigs:'deploy.yaml',kubeConfig:[path:''],kubeconfigId:'9c1da035-60b9-4bd8-aeae-1a31666280ce',secretName:'',ssh:[sshCredentialsId:'*',sshServer:''],textCredentials:[certificateAuthorityData:'',clientCertificateData:'',clientKeyData:'',serverUrl:'https://']}else{echo"跳过Deployk8s"}}}}}
 </div> <div class="zixun-tj-product adv-bottom"></div> </div> </div> <div class="prve-next-news">
本文:k8s的部署脚本是什么的详细内容,希望对您有所帮助,信息来源于网络。
上一篇:RabbitMQ消息有效期与死信的处理过程是什么下一篇:

8 人围观 / 0 条评论 ↓快速评论↓

(必须)

(必须,保密)

阿狸1 阿狸2 阿狸3 阿狸4 阿狸5 阿狸6 阿狸7 阿狸8 阿狸9 阿狸10 阿狸11 阿狸12 阿狸13 阿狸14 阿狸15 阿狸16 阿狸17 阿狸18