{"id":18612456,"url":"https://github.com/alejandro945/my-health-ops","last_synced_at":"2025-11-02T23:30:26.466Z","repository":{"id":155578969,"uuid":"613936095","full_name":"alejandro945/my-health-ops","owner":"alejandro945","description":"My Health App Infrastructure Repository","archived":false,"fork":false,"pushed_at":"2023-05-24T01:28:38.000Z","size":6045,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"dev","last_synced_at":"2024-12-27T02:14:04.136Z","etag":null,"topics":["branch-protection","ci-cd","iot","jenkins","k8s-cluster","mlops","sonarqube"],"latest_commit_sha":null,"homepage":"https:github.com","language":"HCL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alejandro945.png","metadata":{"files":{"readme":"README.MD","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-03-14T15:05:28.000Z","updated_at":"2024-05-15T00:39:15.000Z","dependencies_parsed_at":null,"dependency_job_id":"7fabac53-053e-4083-8dfe-4de1fc080937","html_url":"https://github.com/alejandro945/my-health-ops","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alejandro945%2Fmy-health-ops","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alejandro945%2Fmy-health-ops/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alejandro945%2Fmy-health-ops/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alejandro945%2Fmy-health-ops/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alejandro945","download_url":"https://codeload.github.com/alejandro945/my-health-ops/tar.gz/refs/heads/dev","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239402852,"owners_count":19632466,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["branch-protection","ci-cd","iot","jenkins","k8s-cluster","mlops","sonarqube"],"created_at":"2024-11-07T03:17:14.976Z","updated_at":"2025-11-02T23:30:26.417Z","avatar_url":"https://github.com/alejandro945.png","language":"HCL","funding_links":[],"categories":[],"sub_categories":[],"readme":"# My health Operations 🚀\nThis repository contains the infrastructure as code for the My Health application. Also it has configuration files for the CI/CD pipeline.\n## Infrastructure Provisioning\n\n- What will we build?\n\n    ![Infra](./assets/infra.png)\n\n- About our ingress controller:\n\n    ![ingress](./assets/ingress-diagram.png)\n\n1. Build our infrastructure using terraform with the following command:\n\n```sh\ncd terraform \u0026\u0026 terraform init \u0026\u0026 terraform apply -auto-approve\n```\n\n2. Save your terraform outputs [Our Infrastructure creation last aprox 5 minutes]\n\n![Resources](./assets/az-resources.png)\n\nTo see acr sensitive password on your terminal run the following command:\n\n```sh\nterraform output -no-color acr_password\n```\n\n**Note:** Delete our infrastructure using terraform with the following command:\n\n```sh\nterraform destroy -auto-approve\n```\n\n## Configuration Management\n\n### CouchDB and pipeline slave Ansible Playbook\n\n1. Install Ansible in your local machine\n\n```sh\nsudo apt update\napt-get install ansible\n```\n\n2. Change the IP address in the inventory/hosts file with the public IP address of the VM created in the previous step.\n\n```sh\n[azure_vm]\nazure_vm-host ansible_host=host@X.X.X.X\n```\n\n3. Run our playbook with the following command:\n\n```sh\ncd ansible \u0026\u0026 ansible-playbook -i hosts.yml playbook.yml --extra-vars \"@secrets.yml\" -e \"ansible_ssh_pass={{ansible_password}}\" --ssh-extra-args='-o StrictHostKeyChecking=no'\n```\n![Ansible](./assets/ansible.png)\n\nWait for 1 minutes [User Binding] and then run the following playbook:\n\n```sh\nansible-playbook -i hosts.yml db.yml --extra-vars \"@secrets.yml\" -e \"ansible_ssh_pass={{ansible_password}}\" --ssh-extra-args='-o StrictHostKeyChecking=no'\n```\n\n### Kubernetes bash script\n\n1. Go to your kubeconfig file in your local machine\n\n```sh\ncd ~/.kube\n```\n\n**Note: For delete an specific context in your kubeconfig file**\n\n```sh\nkubectl config get-contexts\nkubectl config delete-context $1\n```\n\n2. Azure kubeconfig file configuration where $1 is the resource group name and $2 is the cluster name.\n\n```sh\naz aks get-credentials --resource-group my-health-rg --name my-health-aks --file ./config\n# Merged \"my-health-aks\" as current context in ./config\n```\n\n3. Get the k8s context and then change the kubeconfig file\n\n```sh\nkubectl config get-contexts\nkubectl config use-context $1\n```\n4. Change our database endpoint, pvc node affinity of jenkins and public jetstack ip address in the following files: (https://www.base64encode.org/)\n\n```sh\n#./k8s/secrets/server-sc.yaml\nhttp://admin:password@X.X.X.X:5984/ \n# already base encoded echo \"http://admin:password@X.X.X.X:5984/\" | base64\n# aHR0cDovL2FkbWluOnBhc3N3b3JkQDIwLjEyNy41Mi4xMjg6NTk4NC8=\n# ./k8s/services/jenkins-svc.yaml\nloadBalancerIP: X.X.X.X # K8S Default public ip address (aks public ip)\n# dev /Jenkinsfile\n# http://52.149.201.78/ in cd trigger\n```\n\n**Optional** Enable ingress addon in our cluster for expose our runners apps [sonar and jenkins] and create ingress yaml\n\n```sh\naz aks enable-addons --addons http_application_routing --name my-health-aks --resource-group my-health-rg\naz aks disable-addons --addons http_application_routing --name my-health-aks --resource-group my-health-rg --no-wait\n``` \n\n5. Configure ACR integration for existing AKS clusters. The az aks update --attach-acr command uses the permissions of the user running the command to create the ACR role assignment. This role is assigned to the kubelet managed identity [3 minutes]\n\n```sh\naz aks update -n my-health-aks -g my-health-rg --attach-acr myHealthContainerRegistry\n```\n\n6. Run our bash script with the following command:\n\n```sh\ncd k8s \u0026\u0026 chmod 777 deploy.sh \u0026\u0026 ./deploy.sh\n```\n![k8s](./assets/k8s.png)\n\n7. See nginx ingress public ip address or client service public ip address\n\n```sh\nkubectl get svc -n client\n# Optional\nkubectl get svc -n kube-system\n```\n\n8. Unlock jenkins server\n\n- Get jenkins public ip address\n\n```sh\nkubectl get svc -n runners\n```\n\n- Go to jenkins public ip address and unlock jenkins with the following command:\n\n```sh\nkubectl exec -it -n runners $(kubectl get pods -n runners | grep jenkins | awk '{print $1}') -- cat /var/jenkins_home/secrets/initialAdminPassword\n#admin - 847b07c1a71d494eab2de1d4a4e1479a\n```\n\n- Install default plugins continue as admin and save and finish\n\n### CI / CD Pipeline configuration\n\n#### Sonarqube configuration\n\n- Go to sonarqube public ip address and login with admin and admin credentials\n\n- Create token in administration -\u003e security -\u003e users -\u003e admin -\u003e generate token\n\n- Change admin permissions to user in administration -\u003e security -\u003e users -\u003e admin -\u003e permissions -\u003e apply all\n\n#### Jenkins configuration\n\n- Configure node runner in manage jenkins -\u003e manage nodes and clouds -\u003e new node and add node with the following configuration: docker-agent as name, vm ip address, remote root directory /home/healthadmin/jenkins, permanent agent, launch method: launch agent via ssh, node_credentials: add credentials with username and password, host key verification strategy: non verifying verification strategy\n\n- Gor to admin -\u003e Dashboard -\u003e Configure and Click on Add new Token, write a name 'jenkins_api_token' for it and then press Generate. We need to store this Token in a safe place because there is no way to recover it in the future unless creating a new one.\n\n- Go to admin -\u003e Credentials -\u003e System -\u003e Global credentials -\u003e Add credentials and add:\n\n    1. Sonarqube server with sonar_credentials as id and secret text for sonar server token.\n    2. Username and password for github.\n    3. Username with password for acr_credentials. \n    4. Secret text for jenkins_api_token for trigger cd pipeline as jenkins_api_token.\n\n![auth](./assets/token.png)\n\n- Install sonarqube scanner in manage jenkins -\u003e manage plugins -\u003e available and install without restart.\n\n- Go to manage jenkins -\u003e Global tool configuration and add sonarqube scanner with **sonar** as name\n\n- Go to manage jenkins -\u003e Configure system -\u003e sonarqube servers and check env variables nad add sonarqube server with sonar as name and http://sonar-svc.runners.svc.cluster.local:9000 as server url and auth token as sonar-credentials\n\n- Configure your CI pipeline, go create a job, select pipeline and enter dev-pipeline as name. Then select GitHub project with the following url: https://github.com/alejandro945/my-health-dev, GitHub hook trigger for GITScm polling and Pipeline script from SCM main branch.\n\n- Configure your CD pipeline, go create a job, select pipeline and enter ops-pipeline as name. Then select discard old builds with max of 2, select this project is parameterized-string parameter and IMAGE_TAG as name, select trigger builds remotely with **gitops-token** as string, finally Pipeline script from SCM **dev** branch with the following url:https://github.com/alejandro945/my-health-ops.\n\n![pipe](./assets/pipeline.png)\n\n#### Github configuration\n\n1. To create our GitHub Webhook, we need to open our repository and click on settings. Then click on Webhooks and Add webhook\n\n2. Inside the Payload URL text box, we need to write the direction to our Jenkins Server ip, plus: /github-webhook/. The payload must have both / to work, otherwise it'll throw some error. Inside the Secret box, we'll paste the Jenkins API Token from section bellow.\n\nCheck your pipeline creating a commit in your repository. [Build at the first time manually] 💥\n\n#### ArgoCD configuration\n\n1. Get initial password\n\n```sh\nkubectl -n runners get secret argocd-initial-admin-secret -o jsonpath=\"{.data.password}\" | base64 -d\n```\n\n2. Vinculate repository\n\n3. Create Project with my-health as name\n\n4. Enable auto sync\n\n## Evidence of the application running on cloud\n\n### CouchDB\n\n![db](./assets/db.png)\n\n### Client\n\n![client](./assets/client.png)\n\n### Server\n\n```sh\nkubectl port-forward --address 0.0.0.0 service/server-svc --namespace server 20000:80\n```\n![server](./assets/server.png)\n\n### Grafana\n\n```sh\nkubectl port-forward --address 0.0.0.0 service/grafana-service --namespace metrics 30000:80\n# admin - admin\n```\n![grafana](./assets/grafana.png)\n\n### Prometheus\n\n```sh\nkubectl port-forward --address 0.0.0.0 service/prometheus-service --namespace metrics 31000:8080\n```\n![prometheus](./assets/prometheus.png)\n\n### ArgoCD\n\n```sh\nkubectl port-forward --address 0.0.0.0 service/argocd-server --namespace runners 32000:443\n# admin - kubectl -n runners get secret argocd-initial-admin-secret -o jsonpath=\"{.data.password}\" | base64 -d\n```\n\n![argocd](./assets/argocd.png)\n\n### Jenkins\n\n```sh\nkubectl port-forward --address 0.0.0.0 service/jenkins-service --namespace runners 33000:8080\n```\n![jenkins](./assets/jenkins.png)\n\n### SonarQube\n\n```sh\nkubectl port-forward --address 0.0.0.0 service/sonar-svc --namespace runners 34000:9000\n# admin - admin\n# admin - password\n```\n![sonar](./assets/sonarqube.png)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falejandro945%2Fmy-health-ops","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falejandro945%2Fmy-health-ops","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falejandro945%2Fmy-health-ops/lists"}