如何使用 jenkins 部署有状态的应用程序

阿里尔·塔拉扬斯

TL;DR 有谁知道允许部署有状态应用程序的 Jenkins 插件

我正在使用 Jenkins 使用多分支 CI/CD 管道来自动化开发过程。我正在尝试部署一个有状态的应用程序。我正在使用“Kubernetes Continuous Deploy Version1.0.0”插件进行部署,管道按预期正常运行,除了一部分。詹金斯管道状态页面

状态为绿色,但是,有状态集没有在 k8s 集群上启动或更新。当我检查状态时,我的插件似乎正在跳过我提供的 YAML。“将应用程序部署到 Kubernetes”阶段的状态:

            Starting Kubernetes deployment
        Loading configuration: /var/lib/jenkins/workspace/algo-1_master/Preprod/Trader/statefulset_algo_1.yaml
        Skipped unsupported resource: StatefulSet(apiVersion=apps/v1, kind=StatefulSet,
     metadata=ObjectMeta(annotations={}, clusterName=null, creationTimestamp=null, 
    deletionGracePeriodSeconds=null, deletionTimestamp=null, finalizers=[], 
    generateName=null, generation=null, initializers=null, labels={},
     name=algo-1, namespace=1-algo-prod, ownerReferences=[],
     resourceVersion=null, selfLink=null, uid=null, additionalProperties={}),
     spec=StatefulSetSpec(podManagementPolicy=null, replicas=4, revisionHistoryLimit=null, 
    selector=LabelSelector(matchExpressions=[], 
    matchLabels={app=algo-1}, additionalProperties={}), serviceName=algo-1
    , template=PodTemplateSpec(metadata=ObjectMeta(annotations={},
         clusterName=null, creationTimestamp=null, deletionGracePeriodSeconds=null, deletionTimestamp=null, finalizers=[], generateName=null, generation=null,
         initializers=null, labels={app=algo-1}, name=null, namespace=null, ownerReferences=[],
 resourceVersion=null, selfLink=null,
     uid=null, additionalProperties={}), spec=PodSpec(activeDeadlineSeconds=null, affinity=null, automountServiceAccountToken=null, containers=[Container(args=[], command=[], env=[EnvVar(name=PODNAME, value=null,
         valueFrom=EnvVarSource(configMapKeyRef=null, fieldRef=ObjectFieldSelector(apiVersion=null, 
        fieldPath=metadata.name, additionalProperties={}), resourceFieldRef=null,
 secretKeyRef=null, additionalProperties={}), additionalProperties={}), EnvVar(name=API_ID, value=null, 
        valueFrom=EnvVarSource(configMapKeyRef=null, fieldRef=null, resourceFieldRef=null,
         secretKeyRef=SecretKeySelector(key=api-id, name=alpaca-api, optional=null,
 additionalProperties={}), additionalProperties={}), additionalProperties={}),
         EnvVar(name=API_KEY, value=null, valueFrom=EnvVarSource(configMapKeyRef=null, fieldRef=null, resourceFieldRef=null, 
secretKeyRef=SecretKeySelector(key=secret-key, name=alpaca-api, optional=null, additionalProperties={}), 
        additionalProperties={}), additionalProperties={})], envFrom=[], image=arieltar/algo-1,
 imagePullPolicy=Always, lifecycle=null, livenessProbe=null, name=algo-1, ports=[], readinessProbe=null, resources=null, securityContext=null,
         stdin=null, stdinOnce=null, terminationMessagePath=null, terminationMessagePolicy=null,
 tty=null, volumeDevices=[], volumeMounts=[], workingDir=null, additionalProperties={})], dnsConfig=null, 
        dnsPolicy=null, hostAliases=[], hostIPC=null, hostNetwork=null, hostPID=null,
 hostname=null, imagePullSecrets=[], initContainers=[], nodeName=null, nodeSelector={},
 priority=null, priorityClassName=null, restartPolicy=null, schedulerName=null, securityContext=null, 
        serviceAccount=null, serviceAccountName=null, subdomain=null, terminationGracePeriodSeconds=null, tolerations=[], volumes=[], additionalProperties={}),
 additionalProperties={}), updateStrategy=null, volumeClaimTemplates=[], additionalProperties={}), status=null, additionalProperties={})
            Finished Kubernetes deployment

我的管道如下

pipeline {
    environment {
      dockerimagename = "arieltar/algo-1"
      dockerImage = ""
    }

    agent any

    stages {

      stage('Checkout Source') {
        steps {
          git 'https://github.com/finance-dataspider/spiderdoc.git'
        }
      }

      stage('Build image') {
        steps{
          script {
            dockerImage = docker.build(dockerimagename,"./Preprod/Trader/")
          }
        }
      }

      stage('Pushing Image') {
        environment {
                registryCredential = 'dockerhub-reg'
            }
        steps{
          script {
            docker.withRegistry( 'https://registry.hub.docker.com', registryCredential ) {
              dockerImage.push("latest")
            }
          }
        }
      }

      stage('Deploying App to Kubernetes') {
        steps {
          script {
            kubernetesDeploy(configs: "Preprod/Trader/statefulset_algo_1.yaml", kubeconfigId: "kubernetes")
          }
        }
      }

    }

  }
苛刻的曼瓦尔

如果插件不支持有状态集并且您想要部署它,那么简单的解决方案就不要使用它。

只需将kubectl安装到 bash 中并直接使用它来应用 YAML

stage('Deploy Image') {
      steps{
        script {
          docker.withRegistry( '', registryCredential ) {
            dockerImage.push("$BUILD_NUMBER")
             dockerImage.push('latest')

          }
        }
      }
    }
    stage('Deploy to K8s') {
      steps{
        script {
          sh "sed -i 's,TEST_IMAGE_NAME,harshmanvar/node-web-app:$BUILD_NUMBER,' deployment.yaml"
          sh "cat deployment.yaml"
          sh "kubectl --kubeconfig=/home/ec2-user/config get pods"
          sh "kubectl --kubeconfig=/home/ec2-user/config apply -f deployment.yaml"
        }
      }
    }

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何使用Jenkins部署SpringBoot Maven应用程序?

如何通过Jenkins在EKS中部署kubernetes应用程序

如何使用Jenkins在本地自动部署Play Framework(2.4)应用程序?

检查应用程序是否已部署,如果在 Jenkins 中使用 Bash 部署,则取消部署

如何在安装了Jenkins的情况下部署tomcat Web应用程序

如何从Jenkins将Python应用程序部署到Amazon Elastic Beanstalk?

如何使用Docker部署应用程序

将Snap应用程序与Jenkins一起使用

在Jenkins上部署Spring Boot应用程序

通过jenkins将应用程序部署到kubernetes

如何使用jenkins-cli检查jenkins节点连接状态

如何在 MacOS 上使用 Jenkins 的 appium 测试 iOS 应用程序

如何使用 docker 在 Jenkins 中构建 .net 核心应用程序并将其推送到 ECR?

如何在Jenkins中为.NET应用程序使用ini文件?

如何设置 Jenkins 以构建使用 Carthage 的 React Native iOS 应用程序?

在Spring Boot应用程序的应用程序属性文件中使用Jenkins变量

如何修复 gcloud 应用程序部署错误 Cloud build failed。失败状态:未知?

如果有人使用Java应用程序,如何部署

如何使用其他Linux平台中的所有dll文件部署Qt应用程序?

如何部署Spark Streaming应用程序?

如何部署Dropwizard应用程序

如何部署 Go Web 应用程序

您如何部署Angular应用程序?

有状态应用程序的 Kubernetes 部署

使用RXTX部署独立的应用程序

使用 Kubernetes 部署 Quarkus 应用程序

如何部署使用Redis的Meteor应用程序?

如何使用Qt部署跨平台应用程序?

如何部署.NET Web应用程序使用PowerShell天青