Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The last updated of application - 10/11/2021 #2

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"formulahendry.vscode-mysql"
]
}
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM python:3.8-alpine
RUN apk add gcc musl-dev mariadb-connector-c-dev
COPY requirements.txt /tmp
WORKDIR /tmp
RUN pip install --upgrade pip && \
pip install -r requirements.txt
RUN mkdir /app
WORKDIR /app
COPY app.py .
ENTRYPOINT [ "python" ]
CMD [ "app.py" ]
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
# devops-python-app
Simple Python app code for DevOps challenges
This application is a simple web application that keeps the scores of devops and prints it to the screen. The application was developed with python and was used flask web framework. Mysql is used as database. The libraries required for the application are also available in requirement.txt.

The application contains docker container. The Docker image runs on Alpine Linux. Kubernetes engine is used for container orchestration.

Two separate branches were created for the application. One of them is the local branch and the other is the main branch. The application developer develops and tests the code on its own environment. It then merges the changes into the main branch. The change on the main branch is automatically detected and deployment is made to the product environment.

Kubernetes secrets and configMaps are used for application variables on product environment. In the local development environment, the variables are kept on the OS environment variable.

Google cloud build is used for CI/CD pipeline process. When a change is detected in the main branch, cloud build creates a new docker image and deploys the new image to kubernetes.
12 changes: 12 additions & 0 deletions k8s/configMap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: "v1"
kind: "ConfigMap"
metadata:
name: "python-app-config-mrqi"
namespace: "default"
labels:
app: "python-app"
env: "prod"
data:
MYSQL_INSTANCE_NAME: "db_vngrs"
MYSQL_PORT_3306_TCP_ADDR: "10.69.32.3"
MYSQL_PORT_3306_TCP_PORT: "3306"
50 changes: 50 additions & 0 deletions k8s/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
apiVersion: "apps/v1"
kind: "Deployment"
metadata:
name: "python-app"
namespace: "default"
labels:
app: "python-app"
env: "prod"
spec:
replicas: 1
selector:
matchLabels:
app: "python-app"
env: "prod"
template:
metadata:
labels:
app: "python-app"
env: "prod"
spec:
containers:
- name: "vngrs-sha256-1"
image: "gcr.io/kubernetesproject-328818/vngrs@sha256:71440017a605152d99328ee78b264268327d4b7efb0c8eb0255901232616b2dd"
env:
- name: "MYSQL_INSTANCE_NAME"
valueFrom:
configMapKeyRef:
key: "MYSQL_INSTANCE_NAME"
name: "python-app-config-mrqi"
- name: "MYSQL_PORT_3306_TCP_ADDR"
valueFrom:
configMapKeyRef:
key: "MYSQL_PORT_3306_TCP_ADDR"
name: "python-app-config-mrqi"
- name: "MYSQL_PORT_3306_TCP_PORT"
valueFrom:
configMapKeyRef:
key: "MYSQL_PORT_3306_TCP_PORT"
name: "python-app-config-mrqi"
- name: "MYSQL_USERNAME"
valueFrom:
secretKeyRef:
key: "MYSQL_USERNAME"
name: "credentials"
- name: "MYSQL_PASSWORD"
valueFrom:
secretKeyRef:
key: "MYSQL_PASSWORD"
name: "credentials"
21 changes: 21 additions & 0 deletions k8s/hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
apiVersion: "autoscaling/v2beta1"
kind: "HorizontalPodAutoscaler"
metadata:
name: "python-app-hpa-vc7c"
namespace: "default"
labels:
app: "python-app"
env: "prod"
spec:
scaleTargetRef:
kind: "Deployment"
name: "python-app"
apiVersion: "apps/v1"
minReplicas: 1
maxReplicas: 2
metrics:
- type: "Resource"
resource:
name: "cpu"
targetAverageUtilization: 80
9 changes: 9 additions & 0 deletions k8s/secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: v1
data:
MYSQL_PASSWORD: none
MYSQL_USERNAME: none
kind: Secret
metadata:
name: credentials
namespace: default
type: Opaque
20 changes: 20 additions & 0 deletions k8s/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: v1
kind: Service
metadata:
labels:
app: python-app
env: prod
name: python-app-76rl8
namespace: default
spec:
externalTrafficPolicy: Cluster
ports:
- nodePort: 32346
port: 80
protocol: TCP
targetPort: 3000
selector:
app: python-app
env: prod
sessionAffinity: None
type: LoadBalancer
177 changes: 177 additions & 0 deletions kubernetes/autodeployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: python-app
env: prod
name: python-app
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: python-app
env: prod
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
labels:
app: python-app
env: prod
spec:
containers:
- env:
- name: MYSQL_INSTANCE_NAME
valueFrom:
configMapKeyRef:
key: MYSQL_INSTANCE_NAME
name: python-app-config-mrqi
- name: MYSQL_PORT_3306_TCP_ADDR
valueFrom:
configMapKeyRef:
key: MYSQL_PORT_3306_TCP_ADDR
name: python-app-config-mrqi
- name: MYSQL_PORT_3306_TCP_PORT
valueFrom:
configMapKeyRef:
key: MYSQL_PORT_3306_TCP_PORT
name: python-app-config-mrqi
- name: MYSQL_USERNAME
valueFrom:
secretKeyRef:
key: MYSQL_USERNAME
name: credentials
- name: MYSQL_PASSWORD
valueFrom:
secretKeyRef:
key: MYSQL_PASSWORD
name: credentials
image: >-
gcr.io/kubernetesproject-328818/github.com/emrahbickingc/devops-python-app
imagePullPolicy: IfNotPresent
name: vngrs-sha256-1
---
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
labels:
app: python-app
env: prod
managedFields:
- apiVersion: autoscaling/v2beta1
fieldsType: FieldsV1
fieldsV1:
'f:metadata':
'f:annotations':
.: {}
'f:kubectl.kubernetes.io/last-applied-configuration': {}
'f:labels':
.: {}
'f:app': {}
'f:env': {}
'f:spec':
'f:maxReplicas': {}
'f:metrics': {}
'f:minReplicas': {}
'f:scaleTargetRef':
'f:apiVersion': {}
'f:kind': {}
'f:name': {}
manager: kubectl-client-side-apply
operation: Update
time: '2021-10-12T21:40:24Z'
- apiVersion: autoscaling/v1
fieldsType: FieldsV1
fieldsV1:
'f:metadata':
'f:annotations':
'f:autoscaling.alpha.kubernetes.io/conditions': {}
'f:status':
'f:currentReplicas': {}
manager: vpa-recommender
operation: Update
time: '2021-10-12T21:40:40Z'
name: python-app-hpa-vc7c
namespace: default
spec:
maxReplicas: 2
metrics:
- resource:
name: cpu
targetAverageUtilization: 80
type: Resource
minReplicas: 1
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: python-app
---
apiVersion: v1
kind: Service
metadata:
finalizers:
- service.kubernetes.io/load-balancer-cleanup
generateName: python-app-
labels:
app: python-app
env: prod
managedFields:
- apiVersion: v1
fieldsType: FieldsV1
fieldsV1:
'f:metadata':
'f:generateName': {}
'f:labels':
.: {}
'f:app': {}
'f:env': {}
'f:spec':
'f:externalTrafficPolicy': {}
'f:ports':
.: {}
'k:{"port":80,"protocol":"TCP"}':
.: {}
'f:port': {}
'f:protocol': {}
'f:targetPort': {}
'f:selector':
.: {}
'f:app': {}
'f:env': {}
'f:sessionAffinity': {}
'f:type': {}
manager: GoogleCloudConsole
operation: Update
time: '2021-10-12T22:47:29Z'
- apiVersion: v1
fieldsType: FieldsV1
fieldsV1:
'f:metadata':
'f:finalizers':
.: {}
'v:"service.kubernetes.io/load-balancer-cleanup"': {}
'f:status':
'f:loadBalancer':
'f:ingress': {}
manager: kube-controller-manager
operation: Update
time: '2021-10-12T22:48:23Z'
name: python-app-76rl8
namespace: default
spec:
clusterIP: 10.44.12.96
externalTrafficPolicy: Cluster
ports:
- nodePort: 32346
port: 80
protocol: TCP
targetPort: 3000
selector:
app: python-app
env: prod
sessionAffinity: None
type: LoadBalancer
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
flask
mysqlclient