# Deploying Your First Application with Argo CD
Now that you have a good understanding of Argo CD, let's dive into deploying your first application using this powerful tool. We’ll walk you through the entire process, from creating a sample application to monitoring your deployment. By the end, you should feel confident in using Argo CD to manage your Kubernetes applications.
## Prerequisites
Before we get started, make sure you have:
1. **Access to a Kubernetes Cluster**: You can use a local cluster with Minikube, KinD, or a cloud provider such as GKE, AKS, or EKS.
2. **Argo CD Installed**: If you haven’t installed Argo CD yet, you can follow these commands:
```bash
kubectl create namespace argocd
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
-
kubectl CLI: Ensure your
kubectlcommand-line tool is configured to communicate with your Kubernetes cluster. -
Git Repository: A git repository (could be on GitHub, GitLab, etc.) containing the Kubernetes manifests for your application.
Step 1: Create Sample Application
For this example, let’s create a simple "Hello World" web application using a basic Nginx deployment. Start by creating a directory for your application manifests locally.
mkdir my-hello-world-app
cd my-hello-world-app
Create the following directory structure:
my-hello-world-app/
│
├── deployment.yaml
├── service.yaml
└── kustomization.yaml
deployment.yaml
This file will define your application deployment.
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-world
labels:
app: hello-world
spec:
replicas: 1
selector:
matchLabels:
app: hello-world
template:
metadata:
labels:
app: hello-world
spec:
containers:
- name: hello-world
image: nginx:alpine
ports:
- containerPort: 80
service.yaml
This file defines a service to expose your application.
apiVersion: v1
kind: Service
metadata:
name: hello-world
spec:
type: LoadBalancer
ports:
- port: 80
targetPort: 80
selector:
app: hello-world
kustomization.yaml
This file combines your deployment and service for ease of use.
resources:
- deployment.yaml
- service.yaml
Now, you can push this directory to your git repository to make it available for Argo CD.
Step 2: Create a New Application in Argo CD
After pushing your code to your git repository, navigate to the Argo CD dashboard (http://
kubectl port-forward svc/argocd-server -n argocd 8080:443
You’ll need to log in to Argo CD. The username is admin, and the password can be retrieved with the following command:
kubectl get pods -n argocd
kubectl describe secret argocd-initial-admin-secret -n argocd
Navigate to the "Applications" section, and click "New Application".
Application Configuration
Fill out the form with the following configurations:
-
Application Name:
hello-world -
Project:
default -
Source:
- Repository URL:
https://github.com/<your-username>/my-hello-world-app.git(replace with your actual repository URL) - Revision:
HEAD - Path:
.or the specific path if you change it.
- Repository URL:
-
Destination:
- Cluster:
https://kubernetes.default.svc - Namespace:
default(or any other namespace where you want to deploy)
- Cluster:
-
Sync Policy: Use
manualfor starters; this keeps you in control.
Click Create.
Step 3: Sync Your Application
Your application should now be listed in the Argo CD dashboard in an "OutOfSync" state. This means that while Argo CD can see your repository, it hasn't deployed anything yet.
To sync your application, click on the application name, then click the Refresh button, and select Sync from the dropdown:
Sync Options
- You can select
AutomaticorManual. For your first deployment, useManual. - After making your selection, click
Synchronize.
A new dialog box will pop up displaying a summary of changes that will be made. Confirm by clicking Synchronize once more.
Step 4: Verify Your Deployment
After a successful sync, you can check the application status in the dashboard. You should see it moving from OutOfSync to Synced.
To verify that your application is running, you can either:
-
Visit the external IP (if you used a
LoadBalancertype service):kubectl get svc -
Or access the application using port-forwarding:
kubectl port-forward svc/hello-world 8080:80Open your browser and navigate to
http://localhost:8080.
Step 5: Workflow Validation
Make a change in your application code or manifests. For example, you can edit the deployment.yaml file to change the image tag from nginx:alpine to nginx:latest and push the changes to your git repository:
image: nginx:latest
Return to the Argo CD dashboard where you should see the application becoming OutOfSync again. You can resync the application as you did earlier to apply the updates.
Monitoring and Managing the Application
In addition to syncing changes, Argo CD provides powerful monitoring tools. You can view logs, health status, and metrics directly in the UI.
Rollback a Deployment
If something goes wrong or you want to revert back to a previous version, you can use the history and rollback features in Argo CD. Click on the "History" tab in your application view, and choose the desired previous revision to roll back.
Conclusion
Congratulations! You've successfully deployed your first application using Argo CD. With this powerful continuous deployment tool, you can be assured of a smooth experience managing your Kubernetes applications.
As you continue exploring Argo CD, consider diving deeper into advanced topics like automated health checks, self-healing applications, and integrating with CI/CD pipelines. Happy deploying!