It's Capstone Udacity project to actually apply DevOps engineer skills and it requires a few steps:
-
Test project code using linting.
-
Build and test a Docker file to containerize the application.
-
build the image and push it to dockerhub.
-
Create a kubernetes deployment and test it locally with minikube.
-
Create our deployment file that is going to use the image that is in docker hub.
-
Create a service that makes the containers publicly accessible.
-
Create a cluster locally using minikube.
-
Deploy the service and the deployment to the cluster locally and test that the application works.
-
Project demonstrate implemnting docker image and kubernetes using Circleci pipeline.
-
In this project Circleci orbs has been used:
- circleci/[email protected]
- circleci/[email protected]
-
Create a Circleci pipeline to automate the processes:
- linting.
- building the docker image.
- pushing the image to dockerhub.
- deploying the containers to the kubernetes cluster.
-
Upload a complete Github repo with CircleCI to indicate that the code has been tested.
requirements.txt
: all dependencies to be installed.app.py
: The python API starter source code.Makefile
: the defination of the helper commands.Dockerfile
: defination of the container content.deployment.yml
: deployment file that is going to use the image that is in docker hub, also contains a service that makes the containers publicly accessible.config.yml
: circleci configuration file that is going to automate everything in this project.
-
Create a virtualenv and activate it:
python3 -m venv .devops-proj4 && source ~/.devops-proj4/bin/activate
-
Run
make install
to install the dependencies defined in requirements.txt file -
optional test app.py:
python app.py
-
run lint:
make lint
-
build and upload docker by completing the two files
./run_docker.sh
and./upload_docker.sh
, then- Setup requirements for docker such as Login credentials.
- Run app.py in Docker:
./run_docker.sh
- Upload it:
./upload_docker.sh
-
Kubernetes instructions and steps as following:
- Setup requirements for kubernetes such as installing minikube and hypervisor.
- First start your minikube cluster: (
minikube start
) - run script
run_kubernetes.sh
- apply the
deployment.yml
locally that is going to make the containers publicly accessible
steps:
- checkout
- restore_cache:
keys:
- v1-dependencies-{{ checksum "requirements.txt" }}
- v1-dependencies-
- run:
name: install dependencies
command: |
python3 -m venv venv
. venv/bin/activate
make install
# Install hadolint
sudo wget -O /bin/hadolint https://github.com/hadolint/hadolint/releases/download/v1.16.3/hadolint-Linux-x86_64 &&\
sudo chmod +x /bin/hadolint
- save_cache:
paths:
- ./venv
key: v1-dependencies-{{ checksum "requirements.txt" }}
- run:
name: run lint
command: |
. venv/bin/activate
make lint
Creating the infrastructure using orbs circleci/[email protected]
aws-eks/create-cluster:
cluster-name: gsvcapstone
parameters:
cluster-name:
description: |
proj5-capstone1
type: string
steps:
- checkout
- kubernetes/install
- aws-eks/update-kubeconfig-with-authenticator:
cluster-name: << parameters.cluster-name >>
install-kubectl: true
- kubernetes/create-or-update-resource:
get-rollout-status: true
resource-file-path: deployment.yml
resource-name: deployment/proj5-capstone1
aws-eks/update-container-image:
cluster-name: gsvcapstone
container-image-updates: gsvcapstone=proj4mlmicroservice/proj5-capstone
post-steps:
- kubernetes/delete-resource:
resource-names: proj5-capstone
resource-types: deployment
wait: true
record: true
requires:
- create-deployment
resource-name: deployment/proj5-capstone
parameters:
cluster-name:
description: |
proj5-capstone1
type: string
steps:
- kubernetes/install
- aws-eks/update-kubeconfig-with-authenticator:
cluster-name: << parameters.cluster-name >>
- run:
name: Test cluster
command: |
kubectl get svc
kubectl get nodes
kubectl get deployment