add kubectl deploy stage

This commit is contained in:
Nana Janashia
2020-12-05 10:12:03 +01:00
parent d2bb88b269
commit c22ccead98
3 changed files with 43 additions and 1 deletions

9
Jenkinsfile vendored
View File

@@ -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 -'
}
}
}

View File

@@ -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

11
kubernetes/service.yaml Normal file
View File

@@ -0,0 +1,11 @@
apiVersion: v1
kind: Service
metadata:
name: $APP_NAME
spec:
selector:
app: $APP_NAME
ports:
- protocol: TCP
port: 80
targetPort: 8080