diff --git a/Jenkinsfile b/Jenkinsfile index 3220d0f..bd41346 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -40,9 +40,16 @@ pipeline { } } stage('deploy') { + environment { + AWS_ACCESS_KEY_ID = credentials('jenkins_aws_access_key_id') + AWS_SECRET_ACCESS_KEY = credentials('jenkins-aws_secret_access_key') + APP_NAME = 'java-maven-app' + } steps { script { - echo 'deploying docker image to EC2...' + echo 'deploying docker image...' + sh 'envsubst < kubernetes/deployment.yaml | kubectl apply -f -' + sh 'envsubst < kubernetes/service.yaml | kubectl apply -f -' } } } diff --git a/kubernetes/deployment.yaml b/kubernetes/deployment.yaml new file mode 100644 index 0000000..eb6d11c --- /dev/null +++ b/kubernetes/deployment.yaml @@ -0,0 +1,24 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: $APP_NAME + labels: + app: $APP_NAME +spec: + replicas: 2 + selector: + matchLabels: + app: $APP_NAME + template: + metadata: + labels: + app: $APP_NAME + spec: + imagePullSecrets: + - name: my-registry-key + containers: + - name: $APP_NAME + image: nanajanashia/demo-app:$IMAGE_NAME + imagePullPolicy: Always + ports: + - containerPort: 8080 diff --git a/kubernetes/service.yaml b/kubernetes/service.yaml new file mode 100644 index 0000000..a8f25ef --- /dev/null +++ b/kubernetes/service.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: Service +metadata: + name: $APP_NAME +spec: + selector: + app: $APP_NAME + ports: + - protocol: TCP + port: 80 + targetPort: 8080