Introduction
In our previous two blogs, we discussed the world of Helm charts, exploring their benefits and guiding you through the process of creating custom Helm charts for your applications and deploying them on your Kubernetes cluster using the Helm CLI. In this part, we shift our focus to deploying Helm charts through Argo CD and receiving notifications about your application’s status.
Prerequisite
- You should read and perform the previous two blogs, Helm part-01 and Helm part-02.
1.1. Part-1:How to use Helm in Kubernetes?
1.2 Part-2: How to Create a Custom Helm Chart? - Up and running Kubernetes cluster
- Understanding about Helm and Argo CD
What is Argo CD?
Argo CD is a key component of GitOps, a methodology for continuous deployment (CD) of applications. It automates the deployment process, ensuring that changes committed to your Git repository, trigger automatic deployment to your Kubernetes cluster. Argo CD commonly integrates with GitHub or Helm repositories, serving as a centralized source of truth for managing and deploying applications.
To know more about Argo CD, go through the below doc,
Argo CD – Declarative GitOps CD for Kubernetes
Step-01: Install Argo CD on Your Cluster
You can install Argo CD on your Kubernetes cluster with the help of Helm chart or directly by using the kubectl utility; below are the commands for it:
1. kubectl create namespace argocd
2. kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
Step-02: Access The Argo CD Server
As you execute the above command on your cluster, it will install all the necessary components required for running Argo CD smoothly. The command creates an Argo CD service with the default type. For those familiar with Kubernetes services, you may know that services with default type cannot be accessed from outside the cluster. Therefore, we need to change its type.
Use the following command for this purpose:
1. kubectl patch svc argocd-server -n argocd -p ‘{“spec”: {“type”: “NodePort”}}’
After running the above command, we are changing the services to NodePort and hence making it accessible using the Node IP.
1. kubectl get svc -n argocd command
Access Argo CD server- http://<nodeip>:<nodeport>
Step-03: Login Into The Server
After landing on the homepage of Argo CD, you will be prompted to enter a username and password. The username is ‘admin’ for all installations, but the password is randomly generated and needs to be retrieved.
Use the following command to retrieve the password:
1. kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath=”{.data.password}” | base64 -d
Copy the password and login into the Argo CD server.
Step-04: Connecting Argo CD With The Source Repo
After logging into the Argo CD server, the next step is to connect our source repository. Argo CD provides various options for connecting to the source repository. You can deploy Kubernetes manifests stored in your repository directly to the cluster or use Helm charts.
To connect Argo CD Helm charts to the source repo, you need to select the appropriate type of connection.
Let’s proceed to connect our source with Argo CD,
Step-05: Creating A Slack Bot and Slack Channel for Receiving Notifications
Now, we need to create a Slack bot and a Slack channel. Then, add this bot to the respective channel where you want to receive notifications. You can refer to the official Argo CD documentation for detailed instructions on how to set up Slack integration.
Note: While performing this step, you will receive a token. Make sure to store it securely, as we will need it for the subsequent steps. The token appears as a long string starting with ‘<xoxb-…>’
Step-06: Integrating ArgoCD and Slack
Now that you have obtained the token, we need to add it to the ‘argocd-notification’ secret and ‘argocd-notification-configmap’. Use the following command to accomplish this:
1. kubectl patch secret argocd-notifications-secret -n argocd \
2. –type merge –patch ‘{“stringData”:{“slack-token”: “xoxb-………your-token…………”}}’
3.
4. kubectl patch configmap argocd-notifications-cm -n argocd –type merge -p ‘{“data”: {“service.slack”: “token: $slack-token”}}’
After running the above command, you will receive an output indicating that the ‘argocd-notification-secret’ and the corresponding ConfigMap have been successfully patched.
Step-07: Creating An Application Which Can be Deployed on Kubernetes Cluster
After completing the previous step, we are now ready to create an application and receive notifications about its status on our Slack channel, which we configured in the previous steps.
Let’s proceed to create the application through the Argo CD UI.
Note- if you are following along with us, use the below manifest or else make necessary changes and then use it,
1. apiVersion: argoproj.io/v1alpha1
2. kind: Application
3. metadata:
4. name: argocd-slack|
5. annotations:
6. notifications.argoproj.io/subscribe.on-sync-succeeded.slack: argocd-slack
7. notifications.argoproj.io/subscribe.on-sync-failed.slack: argocd-slack
8. spec:
9. destination:
10. server: ‘https://kubernetes.default.svc’ # Kubernetes API server address
11. namespace: default # Namespace where the application will be deployed
12. source:
13. repoURL: https://github.com/Ghaterishi/frontend-argocd.git
14. targetRevision: HEAD
15. path: frontend-chart # Path to the Helm chart directory in your repository
16. helm:
17. valueFiles:
18. – values.yaml # Optional: specify Helm values files
19. project: default # Project within ArgoCD where the application belongs
20. syncPolicy:
21. automated:
22. prune: true
23. selfHeal: true
After creating the application, you will instantly receive a notification on Slack indicating that it is ‘OutOfSync’. However, don’t worry, as we need to add more notification annotations to receive further notifications, such as
Step-08: Add More Annotation to Your Application to Receive Correct Notification About Application Status
As soon as you complete this step you will get another notification like below,
Step-09: Access The Application
After successfully deploying your application, navigate to your Argo CD Kubernetes cluster and check the status and port of the service by running the following command:
1. kubectl get svc
access url- http://<nodeip>:<nodeport> and we will land up on the below page,
Disclaimer
In this blog, we are using a public GitHub repository as our source, which is not ideal for production environments. In production, it’s recommended to use a private source repository. When connecting a private repository with Argo CD, you will need a Personal Access Token (PAT) and a username. You may notice that we left these fields blank when connecting the repository, as our repository is public. Also please use Publicly available images, the images used in this demo are private we can’t pull them or else you will get imagepullbackoff error.
Conclusion
This comprehensive blog provides a detailed guide on using Argo CD for your continuous delivery (CD) pipeline. We’ve learned how to smoothly deploy applications on a Kubernetes cluster using Argo CD and receive real-time notifications for application status updates. By leveraging Argo CD’s capabilities, teams can streamline their deployment processes and ensure greater visibility into the status of their applications.
Now that you are familiar with how to successfully do Argo CD Helm-slack integration, we encourage you to try it on your own.
To get access to more such informational do-it-yourself blogs and practical tech advice, visit our website CloudZenia.
Happy learning!
Leave a Reply