Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the deployment script for K8s

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article focuses on "what is the deployment script for K8s". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what is the deployment script for K8s"?

Talking about docker

Docker can be compared to jvm,jvm and virtual machine, then the image of docker can be compared to jar package, jar runs in jvm, image runs in docker container, and jar package is built through maven's pom.xml definition, and docker also has a Dockerfile to define the packaged image. Before containerization, the final product provided by our development is jar. After containerization, we need to provide an image of docker, the image of docker will contain our jar, and then provide a stable and portable operating environment. Here is the simplest docker image build:

Through docker build-t kl/sales. You can build a runnable image.

Talking about the deployment script of k8s

In fact, there is nothing to say about the script of K8s. There are many concepts of K8s. For details, please refer to the official documentation. Our deployment file is posted below.

ApiVersion: extensions/v1beta1kind: Deploymentmetadata: name: sales-app namespace: # namespacespec: replicas: 2 minReadySeconds: 130# from container startup to normal service provided by the application strategy: # K8s update policy type: RollingUpdate # maximum number of containers allowed to surge when rolling update rollingUpdate: maxSurge: 2 # default replicas maxUnavailable 4 rounding up maxUnavailable: 1 # maximum number of unavailable containers allowed for update The default replicas's 1xxx-vpc.cn-xx.aliyuncs.com/keking/sales:#Tag imagePullPolicy 4 rounded down template: metadata: labels: app: sales-app spec: imagePullSecrets: # Image pull key-name: xx-xx-xx containers:-name: sales image: xxx-vpc.cn-xx.aliyuncs.com/keking/sales:#Tag imagePullPolicy: Always env:-name: runShell value: # RunShell ports:-containerPort: 6002 name: web protocol: TCP resources: limits: cpu: 600m memory: 4Gi requests: cpu: 300m memory: 100Mi livenessProbe: # check for survival httpGet: path: / health port: 6002 InitialDelaySeconds: 240 # how long after the first check periodSeconds: 180 # check period timeoutSeconds: 3 # timeout failureThreshold: 3 # threshold for failure Three times in a row, readinessProbe: # check whether httpGet: path: / health port: 6002 initialDelaySeconds: 140 # check for the first time periodSeconds: 300 # check period timeoutSeconds: 3 # timeout-apiVersion: v1kind: Servicemetadata: name: sales-app namespace: # namespace labels: app: sales-appspec: Selector: app: sales-app ports:-name: web port: 80 targetPort: 6002 nodePort: 31942 type: NodePort finally talk about jenkins pipeline

Like the general definition of jenkins pipeline, there are two more steps after containerization. One is to build an image of the jar according to the Dockerfile file mentioned earlier, which requires that the host where the jenkins resides must have a docker environment. The second step is to send the deployment script for K8s to the K8s container, which is done through the jenkins kuberneetes plug-in, as detailed in the jenkins script below

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 (' Git Checkout') {checkout ([$class: 'GitSCM', branches: [[name: "/ ${branch}"]], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [credentialsId:' xx' Url: 'http://xx.xx.xx/xx/yudian-salesplatform-boot.git']]])} stage (' Maven Build') {script {if ('true' = = "${build}") {sh "mvn clean install-U-P$ {profile} -Dmaven.test.skip=true "} else {echo" skip maven build "} stage ('Docker Build') {script {if ( 'true' = "${build}") {sh' docker login-u it_sh@keking-group-p x#xxx-vpc.cn-xx.aliyuncs.com docker build-t xx-vpc.cn-xx.aliyuncs.com/keking/sales:$ {Tag}. Docker push xx-vpc.cn-xx.aliyuncs.com/keking/sales:$ {Tag}''} else {echo "skip docker build"} stage ( 'Deploy to K8s') {script {if (' true' = = "${deploy}") {if ('prod' = = "${profile}") {sh' sed-I "s / # namespace/prod/g "deploy.yaml sed-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=prod app.jar%g "deploy.yaml ''} if ('uat' = = "${profile}") {sh' 'sed-I "s/#namespace/uat/g" deploy.yaml Sed-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_docker app.jar%g" deploy.yaml ''} sh 'sed-I' Tag'/ g "deploy.yaml' kubernetesDeploy configs: 'deploy.yaml' KubeConfig: [path:'], kubeconfigId: '9c1da035-60b9-4bd8MuaeaeMel 1a31666280cephaly, secretName:', ssh: [sshCredentialsId:'*', sshServer:'], textCredentials: [certificateAuthorityData:', clientCertificateData:', clientKeyData:'' ServerUrl: 'https://']} else {echo "skip Deploy k8s"} here I believe that you have a deeper understanding of "what is the deployment script of K8s", you might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report