This repository was archived by the owner on Dec 20, 2020. It is now read-only.
File tree 15 files changed +220
-14
lines changed
aws-k8s-pgdb-with-terraform/aws-rds
15 files changed +220
-14
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,6 @@ resource "aws_db_instance" "default" {
18
18
name = " kubernetes101db"
19
19
username = " ${ var . db_username } "
20
20
password = " ${ var . db_password } "
21
- vpc_security_group_ids = [" sg-03dade87817c9c30f " ] # aws_security_group_rule.kube-node-ingress-self
21
+ vpc_security_group_ids = [" sg-e87817c9c30f " ] # aws_security_group_rule.kube-node-ingress-self
22
22
db_subnet_group_name = " ${ aws_db_subnet_group . dbsub . id } "
23
23
}
Original file line number Diff line number Diff line change
1
+ pipeline {
2
+ agent any
3
+ stages {
4
+ stage('Build Docker image') {
5
+ steps {
6
+ sh 'echo "Build and push docker image...:"'
7
+ sh '''#!/bin/bash
8
+ GITREV=`git rev-parse --short HEAD`
9
+ cat /opt/docker-hub-password.txt | docker login -u kubetotorial101 --password-stdin
10
+ docker push kubetotorial101/pollproject:$GITREV
11
+
12
+ '''
13
+ }
14
+ }
15
+ stage('dev environment deploy') {
16
+ steps {
17
+ sh 'echo "Deploy to the development K8s namespace..."'
18
+ sh '''
19
+ export PATH=$HOME/software:$PATH
20
+ kubectl config use-context demo-dev
21
+ GITREV=`git rev-parse --short HEAD`
22
+ git checkout development
23
+ sed -i -e \"s/image:.*/image: kubetotorial101\\/pollproject:$GITREV/g\" kubecode/deployment_django.yaml
24
+ kubectl apply -f kubecode/deployment_django.yaml --record
25
+ sleep 15
26
+ kubectl describe deploy django-deployment
27
+ kubectl describe deploy django-deployment | grep "MinimumReplicasAvailable" | grep "True"
28
+ '''
29
+ }
30
+ }
31
+ stage ('Unit testing') {
32
+ steps {
33
+ sh 'echo "Invoking and performing unit tests inside docker container"'
34
+ }
35
+ }
36
+ stage ('Developer sign-off') {
37
+ steps {
38
+ sh 'echo "Unit testing passed, so pushing changes into devevlopment branch"'
39
+ sh '''
40
+ git commit -a -m "Unit tests passed, developer sign-off"
41
+ git push origin development
42
+ '''
43
+ }
44
+ }
45
+ }
46
+ post {
47
+ always {
48
+ cleanWs()
49
+ }
50
+ }
51
+ }
52
+
Original file line number Diff line number Diff line change
1
+ pipeline {
2
+ agent any
3
+ stages {
4
+ stage('Production promotion') {
5
+ steps {
6
+ sh 'echo "Deploy to the production K8s namespace..."'
7
+ sh '''
8
+ export PATH=$HOME/software:$PATH
9
+ kubectl config use-context demo-prod
10
+ GITREV=`git rev-parse --short HEAD`
11
+ echo "Deploying master branch ($GITREV) to production cluster."
12
+ kubectl apply -f kubecode/deployment_django.yaml --record
13
+ '''
14
+ }
15
+ }
16
+ }
17
+ post {
18
+ always {
19
+ cleanWs()
20
+ }
21
+ }
22
+ }
Original file line number Diff line number Diff line change
1
+ pipeline {
2
+ agent any
3
+ stages {
4
+ stage('Roll back') {
5
+ steps {
6
+ sh 'echo "undo rollout"'
7
+ sh '''
8
+ export PATH=$HOME/software:$PATH
9
+ kubectl config use-context demo-prod
10
+ echo "History BEFORE roll-back"
11
+ kubectl rollout history deployment.v1.apps/django-deployment
12
+ kubectl rollout undo deployment.v1.apps/django-deployment
13
+ echo "History AFTER roll-back"
14
+ kubectl rollout history deployment.v1.apps/django-deployment
15
+ '''
16
+ }
17
+ }
18
+ }
19
+ }
Original file line number Diff line number Diff line change
1
+ pipeline {
2
+ agent any
3
+ parameters {
4
+ string(
5
+ name: 'REPLICAS',
6
+ defaultValue:"2",
7
+ description: "Number of pods running the application server")
8
+ }
9
+ stages {
10
+ stage('Collecting current status') {
11
+ steps {
12
+ sh 'echo "Current replica status"'
13
+ sh '''
14
+ export PATH=$HOME/software:$PATH
15
+ kubectl config use-context demo-prod
16
+ kubectl get pods --selector=app=django
17
+ '''
18
+ }
19
+ }
20
+ stage('Scale app (click to input # replicas') {
21
+ steps {
22
+ sh "echo REPLICAS: ${params.REPLICAS}"
23
+ sh """#!/usr/bin/env bash
24
+ export PATH=$HOME/software:$PATH
25
+ kubectl config use-context demo-prod
26
+ kubectl scale deployment.v1.apps/django-deployment --replicas=${params.REPLICAS}
27
+ """
28
+ }
29
+ }
30
+ stage('Collecting new status') {
31
+ steps {
32
+ sh 'echo "Current replica status"'
33
+ sh '''
34
+ export PATH=$HOME/software:$PATH
35
+ kubectl config use-context demo-prod
36
+ kubectl get pods --selector=app=django
37
+ '''
38
+ }
39
+ }
40
+ }
41
+ }
Original file line number Diff line number Diff line change
1
+ pipeline {
2
+ agent any
3
+ stages {
4
+ stage('Create release candidate') {
5
+ steps {
6
+ sh 'echo "Creating release candidate branch from development."'
7
+ sh '''
8
+ GITREV=`git rev-parse --short HEAD`
9
+ git branch release-candidate-$GITREV
10
+ echo "Release candidate git hash is $GITREV"
11
+ '''
12
+ }
13
+ }
14
+ stage('Integration and Acceptance tests') {
15
+ steps {
16
+ sh 'echo "Running integration and acceptance tests"'
17
+ sh 'echo "Running integration tests"'
18
+ sh 'echo "Running acceptance tests"'
19
+ sh 'echo "ALL tests passed"'
20
+ }
21
+ }
22
+ stage('QA sign-off') {
23
+ steps {
24
+ sh 'echo "Integration and Acceptance tests passed, so merging into master branch"'
25
+ sh '''
26
+ GITREV=`git rev-parse --short HEAD`
27
+ git fetch
28
+ git checkout master
29
+ git merge release-candidate-$GITREV
30
+ git push origin master
31
+ '''
32
+ }
33
+ }
34
+ }
35
+ post {
36
+ always {
37
+ cleanWs()
38
+ }
39
+ }
40
+ }
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ apiVersion: v1
3
3
kind : ConfigMap
4
4
metadata :
5
5
name : postgres-config
6
- namespace : development
6
+ namespace : demo-dev
7
7
data :
8
8
POSTGRES_DB : " kubetutorial101"
9
9
POSTGRES_USER : " postgres"
Original file line number Diff line number Diff line change @@ -3,10 +3,10 @@ apiVersion: v1
3
3
kind : ConfigMap
4
4
metadata :
5
5
name : postgres-config
6
- namespace : production
6
+ namespace : demo-prod
7
7
data :
8
- POSTGRES_DB : " kubernetes101db "
9
- POSTGRES_USER : " kubetutorial101 "
8
+ POSTGRES_DB : " kubetutorial101 "
9
+ POSTGRES_USER : " postgres "
10
10
RUN_IN_PRODUCTION : " True"
11
11
AWS_S3_REGION_NAME : " us-west-2"
12
12
Original file line number Diff line number Diff line change
1
+ {
2
+ "kind" : " Namespace" ,
3
+ "apiVersion" : " v1" ,
4
+ "metadata" : {
5
+ "name" : " demo-dev" ,
6
+ "labels" : {
7
+ "name" : " demo-dev"
8
+ }
9
+ }
10
+ }
Original file line number Diff line number Diff line change
1
+ {
2
+ "kind" : " Namespace" ,
3
+ "apiVersion" : " v1" ,
4
+ "metadata" : {
5
+ "name" : " demo-prod" ,
6
+ "labels" : {
7
+ "name" : " demo-prod"
8
+ }
9
+ }
10
+ }
Original file line number Diff line number Diff line change @@ -18,14 +18,14 @@ spec:
18
18
containers :
19
19
- name : django
20
20
# Notice the tag is also included in the image
21
- image : kubernetes101/django_image:09f1419
21
+ image : kubetotorial101/pollproject:b832173
22
22
ports :
23
23
- containerPort : 8000
24
24
# Minimum and maximum resources allocated to the container.
25
25
resources :
26
26
requests :
27
- memory : " 64Mi "
28
- cpu : " 200m "
27
+ memory : " 32Mi "
28
+ cpu : " 50m "
29
29
limits :
30
30
memory : " 128Mi"
31
31
cpu : " 400m"
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ metadata:
5
5
labels :
6
6
app : postgres
7
7
# A namespace is a virtual k8s cluster
8
- namespace : development
8
+ namespace : demo-dev
9
9
spec :
10
10
# number of pods in the replicaset
11
11
replicas : 1
@@ -27,10 +27,10 @@ spec:
27
27
resources :
28
28
requests :
29
29
memory : " 256Mi"
30
- cpu : " 500m "
30
+ cpu : " 100m "
31
31
limits :
32
32
memory : " 512Mi"
33
- cpu : " 1000m "
33
+ cpu : " 300m "
34
34
envFrom :
35
35
- configMapRef :
36
36
name : postgres-config
Original file line number Diff line number Diff line change @@ -2,8 +2,8 @@ apiVersion: v1
2
2
kind : Service
3
3
metadata :
4
4
name : pghost
5
- namespace : production
5
+ namespace : demo-prod
6
6
spec :
7
7
type : ExternalName
8
- externalName : terraform-20181102201911881300000001 .ctrkthnoul1u.us-west-2.rds.amazonaws.com
8
+ externalName : terraform-20190219195934809500000001 .ctrkthnoul1u.us-west-2.rds.amazonaws.com
9
9
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ apiVersion: v1
2
2
kind : Service
3
3
metadata :
4
4
name : pghost
5
- namespace : development
5
+ namespace : demo-dev
6
6
spec :
7
7
selector :
8
8
app : postgres
Original file line number Diff line number Diff line change
1
+ apiVersion : v1
2
+ kind : Service
3
+ metadata :
4
+ name : pghost
5
+ namespace : demo-prod
6
+ spec :
7
+ selector :
8
+ app : postgres
9
+ ports :
10
+ - protocol : TCP
11
+ port : 5432
12
+ targetPort : 5432
You can’t perform that action at this time.
0 commit comments