App Setup in Argo CD: A Step-by-Step Guide

App Setup in Argo CD: A Step-by-Step Guide

Deploying apps to Kubernetes can be tricky. There are many chances for errors. Inconsistencies pop up. Deployment cycles can drag. What if there was a simpler way?

Argo CD offers a solution! It's a declarative GitOps tool for Kubernetes. Expect improved efficiency, consistency, and reliability. Let's dive in!

Understanding Argo CD

Argo CD is a tool. It makes deploying apps to Kubernetes easier. It follows the GitOps model. This means you manage your infrastructure using Git. Changes to Git trigger automatic updates. It's great for automation and consistency.

What is GitOps?

GitOps is a method. It uses Git as the single source of truth. Configuration lives in Git repositories. Changes are made through pull requests. Automated tools then apply these changes to your cluster.

GitOps has many advantages. Expect better version control. Look forward to quicker rollbacks. Get ready for improved auditability. Declarative configuration management is key! Automated reconciliation ensures the desired state is maintained.

Argo CD Core Concepts

Several concepts are key to Argo CD. Applications represent your deployed services. Repositories store your configuration files. Sources define where Argo CD gets those configurations. Destinations specify which Kubernetes cluster to deploy to.

These components work together. Configuration changes in the repository trigger Argo CD. The tool updates the application in the destination cluster. It aligns it with the desired state in the source.

Argo CD Architecture

Argo CD has a specific structure. The API server handles requests. The repository server fetches configurations. The application controller manages deployments. A UI offers a way to view everything.

Each piece does something important. The API server offers a way to interact. The repository server grabs the necessary code. The application controller makes deployments happen. The user interface offers a visual for deployments.

Setting up MicroK8s

MicroK8s is a lightweight Kubernetes. It's easy to install and configure. It's perfect for development and testing.

Installing MicroK8s

Installing MicroK8s is simple. It works on Linux, macOS, and Windows. Use snap for Linux. Find installation packages for other operating systems.

After installation, start MicroK8s:

microk8s start        

Enabling Addons

MicroK8s has useful add-ons. DNS helps with service discovery. The dashboard offers a UI. Storage allows persistent data. These are important for deploying apps.

Enable these add-ons with:

microk8s enable dns dashboard storage        

These add-ons improve the cluster's functionality. DNS resolves service names. The dashboard offers a visual management tool. Storage makes sure data persists.

Integrating Argo CD with MicroK8s

Connecting Argo CD to MicroK8s is easy. It lets Argo CD manage your apps. It makes deployments simple.

Installing Argo CD

Install Argo CD on MicroK8s using YAML manifests. This automates the installation.

First, create a namespace:

sudo microk8s kubectl create namespace argocd        

Then, apply the manifests:

sudo microk8s kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml        

Configuring Argo CD to Connect to MicroK8s

Configure Argo CD to manage apps on MicroK8s. Create a Kubernetes secret for authentication. This allows secure access to your cluster.

Get the Argo CD admin password:

sudo microk8s kubectl get secret argocd-initial-admin-secret -n argocd -o jsonpath="{.data.password}" | base64 --decode        

Accessing the Argo CD UI

Access the Argo CD UI in your browser. Use the Argo CD server's address. Then, log in with the admin credentials. You can manage your applications there.

First, expose the Argo CD server:

sudo microk8s kubectl patch svc argocd-server -n argocd -p '{"spec": {"type": "NodePort", "ports": [{"port": 443, "targetPort": 8080, "nodePort": 30267}]}}'        

Then, open your browser and go to: https://localhost:30267. Screen will look like below picture.


Enter the admin as username and password which is extracted using above command.

Our homepage of the ArgoCD would be look like below image.


Deploying Applications with Argo CD on MicroK8s

Deploy apps using Argo CD on MicroK8s. It involves creating a project, an application. Then, define resources and monitor the process.

Creating an Argo CD Application

Deploy a Project in Argo CD. Set up the project scope. Define allowed repositories and clusters. Configure namespace restrictions.

Use the Argo CD UI or command line. Declare these settings in the project manifest. This ensures Argo CD enforces deployment boundaries.

Below snippet shows the

apiVersion: argoproj.io/v1alpha1
kind: AppProject
metadata:
  name: local-devops-project
  namespace: argocd
spec:
  description: "Project for managing applications in local-devops namespace"

  destinations:
    - namespace: local-devops
      server: https://kubernetes.default.svc

  sourceRepos:
    - https://github.com/Akash2141/local-devops.git

  clusterResourceWhitelist:
    - group: "*"
      kind: "*"        

Creating an Argo CD Application

Create an Argo CD Application. Tell it the Git repository. Give it the target revision. Specify the destination cluster.

Use the Argo CD UI or command line. Define these parameters in the application manifest. This tells Argo CD where to find the configurations.

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: my-backend-app
  namespace: argocd
spec:
  project: local-devops-project
  source:
    repoURL: https://github.com/Akash2141/local-devops.git
    targetRevision: master
    path: practice-k8s/argocd-k8s
  destination:
    server: https://kubernetes.default.svc
    namespace: local-devops
  syncPolicy:
    automated:
      prune: true
      selfHeal: true
    syncOptions:
      - CreateNamespace=true        

Defining Application Resources

Define application resources using YAML manifests. Follow best practices for resource management. This helps ensure that the applications are configured correctly.

YAML manifests define Kubernetes objects.

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: my-backend-deployment
  name: my-backend-deployment
  namespace: local-devops
spec:
  replicas: 3
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
  selector:
    matchLabels:
      app: my-backend
  template:
    metadata:
      labels:
        app: my-backend
    spec:
      containers:
        - name: my-backend
          imagePullPolicy: IfNotPresent
          image: localhost:32000/my-backend:v2
          ports:
            - containerPort: 8080
          readinessProbe:
            httpGet:
              path: /ready-check
              port: 8080
            initialDelaySeconds: 5
            periodSeconds: 5
          livenessProbe:
            httpGet:
              path: /live-check
              port: 8080
            initialDelaySeconds: 10
            periodSeconds: 10        

Monitoring Application Deployment

Monitor application deployment progress in the Argo CD UI. Troubleshoot any issues. This helps to make sure that deployments go smoothly.

The Argo CD UI shows the status of each resource. It highlights any errors or warnings. It helps you quickly find and fix problems.


Advanced Argo CD Features

Argo CD has many advanced options. These help improve application management. They include sync policies, rollback strategies, and health checks.

Sync Policies

Sync policies control how Argo CD updates applications. Automatic sync updates applications automatically. Manual sync requires approval.

Configure these policies based on your deployment needs. Automatic sync is good for frequent updates. Manual sync is good for sensitive changes.

Health Checks

Configure health checks for applications. This helps ensure they are running correctly. It lets you automatically fix any problems.

Kubernetes offers several types of health checks. Argo CD uses these to monitor applications. It restarts unhealthy pods. It does this automatically.

Conclusion

Argo CD with MicroK8s makes deploying apps easy. Expect improvements in efficiency, consistency, and reliability. Give Argo CD and MicroK8s a try for your Kubernetes deployments.

The main advantages are clear. Deployments are simpler. Consistency is better. Reliability improves.

Now it's your turn to explore Argo CD and MicroK8s. See how they can improve your deployments!

要查看或添加评论,请登录

Akash Gupta的更多文章

社区洞察