'how to deploy stateful applications using jenkins
TL;DR Does anyone knows of a Jenkins plugin that allows to deploy stateful applications
I am using Jenkins to automate the development process using a multibranch CI/CD pipeline.
I'm trying to deploy a stateful application.
I am using the "Kubernetes Continuous Deploy Version1.0.0" plugin for the deploy
the pipeline runs correctly and as expected, except for one part.

the status is green, however, the stateful set isn't starting or updating on the k8s cluster. when I checked the status it seems like my plugin is skipping the YAML I have provided. the status from the "deploying an app to Kubernetes" stage:
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
my pipeline is as follows
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")
}
}
}
}
}
Solution 1:[1]
Easy solution don't use a plugin if it's not supporting stateful set and you want to deploy it.
Just install kubectl into bash and use it directly to apply the 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"
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Harsh Manvar |
