uvicorn main:app --reload
python3 test_main.py
python3 -m unittest appPython/test/test_main.py # From root directory
pip freeze > requirements.txt
docker build -t test_api_python .
docker run -d -p 80:80 test_api_python # Working Docker image
##test application
curl http://localhost:80
docker run -d -p 80:80 garrijuan/test_api_python:latest
minikube start
minikube addons enable ingress
kubectl apply -f k8s/
kubectl describe ingress
curl --location --request GET 'http://apppython'
#Ingress
# When you are using an Ingress and you do not specify a port in your Http request, by default port 80 will be assumed for HTTP requests. This is because Ingress is usually configured to redirect HTTP requests to port 80 for internal Kubernetes services.
make install_argocd # if the cluster havent ArgoCD
kubectl port-forward svc/argocd-server -n argocd 8080:443 #expose argocd app in localhost port 8080
kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d; echo #Return the pass
argocd login localhost:8080
#if we want update the pass, fist login in Argo with the last command, afterwards update the pass with the following command.
#the pass must have a lengh between 8 and 32 characteres
argocd account update-password
To Access ArgoCD application: http://localhost:8080 Enter user and pass: user: admin pass: get with following command
kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d; echo
kubectl create ns staging # create this namespace to deploy on it
#from path /app_python_cicd/apppython/k8s
kubectl apply -f CD.yml #this is a type of resource in kubernetes to deploy application.
when we deploy the application on ArgoCD it isnt syncronized by default, we have to manually do it or enable the autosync
Add the github repository to ArgoCD to monitoring the changes
argocd repo add https://github.com/garrijuan/app-python-CICD.git
the following image is a example a applicaiton correctly syncronice Now, we have syncronice the application and we can a get request and the application return the example message
change the api code to return a different string, and see how it synchronizes automatically.
**image-updater from argoCD has been used, for this we have deployed one more component in the argo installation, also add some annotation in the CRD(CD.yml) to deploy this is necessary to use HELM, the short commit identifier is used as tag.
CLI:
#Ahora podemos relanzar la primera App y sincronizar desde la CLI
argocd app sync apppython
#Si queremos saber el estatus de la App
argocd app get apppython
#Ahora para eliminar las Apps
argocd app delete apppython
helm create apppython
the previous command create a folder with different files, you should update deployment, service, ingress, notes... with your preferences and updated the values in the values.yml file
helm install apppython ./apppython
helm status apppython
helm get values apppython # Values of the current realease
you need a cluster running before use the previos command
helm package apppython/ # pakage me chart in a .tgz
Updated the deploy
helm template mychart ./apppython # muestra todo el deploy
helm package apppython/ # pakage me chart in a .tgz
helm upgrade apppython ./apppython-0.1.0.tgz #deploy the new pakage chart
helm repo index --url https://github.com/garrijuan/app-python-CICD/blob/main/HELM/apppython/charts/ .
#helm repo add argo https://argoproj.github.io/argo-helm
#helm pull argo/argo-cd --version 5.8.2
helm list # List all realease on a cluster
helm list --all # List all realease on a cluster with all status(UNINSTALLED;DEPLOYED, etc)
helm repo list # List the Charts downloaded
delete chart of cluster
helm uninstall apppython
1.Deploy a cluster on EKS ✔️
2.execute --> make install_argocd ✔️
3.install a ingress-nginx with previous HELM chats ✔️
4.login in argocd ✔️
5.test to deploy app with HELM chart apppython ✔️
6.test app is working ✔️
7.delete apppython chart ✔️
8.deploy app from path /app_python_cicd/apppython/k8s ✔️
--> kubectl apply -f CD.yml
9.test app is working ✔️
10.test change in the code and apply directly in the cluster ✔️
#deploy nginx ingress in the cluster to apply a ingress policy
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
helm repo update
kubectl create namespace ingress-nginx
helm install my-nginx-controller ingress-nginx/ingress-nginx --namespace ingress-nginx
kubectl get pods -n ingress-nginx
make install_argocd
we apply the manifest deploy the app in Argocd.
Then we deploy the app in its first version and check on Argocd interface that the application has been deployed correctly.
we check in argocd that the application has been deployed correctly, now we will make a change in the code, for example, message returned = "Hola:Virulo2" . Argo should monitor the image repository, realize that there is a new image and deploy it automatically.
Now we make a change in the internal cluster infrastructure, change the number of replicas and check how argo notices this and deploys it automatically.
In both cases we can see how it detects the commit at the top and how it deploys new pods every time we make a change.
Access to cluster throught the ALB(Load Balancer), the request to the microserver will be make ALB endpoint + specific path of microserver:
curl a7e5caf0b0ff24439a48331ac863e619-270330354.us-east-1.elb.amazonaws.com/api
A DevOps workflow streamlines software development and IT operations by integrating practices like continuous integration, automated testing, deployment automation, and continuous monitoring. It fosters collaboration between development and operations teams, leading to faster delivery of high-quality software. By automating repetitive tasks and promoting a culture of continuous improvement.
In this repository, you can find a example of this flow:
Ideally the developer is working on a microservice, he is making changes on a branch called in this case, DEV, during the working day he is committing changes against the report, these changes are automatically deployed to the pre environment within a k8s cluster and he can immediately see his changes reflected and deployed in this cluster. At the end of the working day, he considers that he must upload those changes to PROD, just do a merge from the dev branch to the main branch and he will automatically see his changes deployed to the cluster in the PROD environment. This is achieved through commit automation and automatic image generation in both environments every time the developer commits changes and automated deployment is achieved through argoCD, a tool deployed in the cluster that monitors the artifact repositories to see if there are new artifacts to deploy and also infrastructure repositories in case there are any changes in deployments or similar.
#install argo rollout in cluster
kubectl create namespace argo-rollouts
kubectl apply -n argo-rollouts -f https://raw.githubusercontent.com/argoproj/argo-rollouts/stable/manifests/install.yaml
steps:
- use chart appython-minikube-rollout we replace deployment.yml to rollout.yml(it is same but add the deploymnet strategy)
- helm package appython-minikube-rollout/
- helm install appython-minikube-rollout ./appython-minikube-rollout
- change the image tag
- generate pkg again -> helm package appython-minikube-rollout
- helm install apppython ./apppython
- helm upgrade apppython-minikube-rollout ./apppython-minikube-rollout-0.1.0.tgz
check deployment
# Get the deployment strategy in a specify namespace
kubectl argo rollouts get rollout apppython-minikube-rollout -n default
kubectl argo rollouts dashboard
# Access to argo release interface
http://localhost:3100