27 Nov 20242 min readJeremy Murray
Adding an Application to ArgoCD Apps or Apps
Adding a simple FastAPI Python app as part of an App of Apps setup in ArgoCD involves several steps. Here’s a step-by-step guide to achieve this:
1. Create Your FastAPI Application
- Ensure your FastAPI app is structured with a
Dockerfilefor containerization and a Kubernetes manifest for deployment.
Directory structure for the FastAPI app:
fastapi-app/
├── app/
│ ├── main.py # Entry point for FastAPI
│ ├── ...
├── Dockerfile # For building the FastAPI app container
├── requirements.txt # Dependencies
├── k8s/
│ ├── deployment.yaml # Kubernetes Deployment manifest
│ ├── service.yaml # Kubernetes Service manifest
Example Dockerfile:
FROM python:3.10-slim
WORKDIR /app
COPY ./requirements.txt /app/requirements.txt
RUN pip install --no-cache-dir -r requirements.txt
COPY ./app /app
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
Kubernetes Manifests:
Example deployment.yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: fastapi-app
labels:
app: fastapi-app
spec:
replicas: 1
selector:
matchLabels:
app: fastapi-app
template:
metadata:
labels:
app: fastapi-app
spec:
containers:
- name: fastapi-app
image: your-docker-repo/fastapi-app:latest
ports:
- containerPort: 8000
Example service.yaml:
apiVersion: v1
kind: Service
metadata:
name: fastapi-app
spec:
selector:
app: fastapi-app
ports:
- protocol: TCP
port: 80
targetPort: 8000
type: ClusterIP
2. Push Your FastAPI App to Git
Push the entire fastapi-app/ directory (with k8s/ manifests) to a Git repository.
3. Define an ArgoCD Application
You’ll need to create an ArgoCD Application YAML for the FastAPI app.
Example fastapi-app.yaml:
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: fastapi-app
namespace: argocd
spec:
project: default
source:
repoURL: 'https://github.com/your-repo/fastapi-app.git'
targetRevision: HEAD
path: k8s
destination:
server: https://kubernetes.default.svc
namespace: default
syncPolicy:
automated:
prune: true
selfHeal: true
4. Add the FastAPI App to the App of Apps
The App of Apps pattern uses a parent ArgoCD Application that manages multiple child Applications.
Parent Application Example:
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: app-of-apps
namespace: argocd
spec:
project: default
source:
repoURL: 'https://github.com/your-repo/app-of-apps.git'
targetRevision: HEAD
path: apps
destination:
server: https://kubernetes.default.svc
namespace: argocd
syncPolicy:
automated:
prune: true
selfHeal: true
In the Git repo for the App of Apps, add the fastapi-app.yaml in the apps/ directory.
Directory structure for the App of Apps repo:
app-of-apps/
├── apps/
│ ├── fastapi-app.yaml
│ ├── another-app.yaml
5. Apply the Parent Application
Once everything is in place, apply the App of Apps manifest:
kubectl apply -f app-of-apps.yaml
This will recursively sync the child applications, including the FastAPI app.
6. Verify Deployment
- Confirm that ArgoCD is syncing the FastAPI app.
- Use
kubectl get podsandkubectl get svcto check the deployment status of the FastAPI app. - Access the FastAPI app via its Service or Ingress, depending on your Kubernetes configuration.
Best Practices
- Use
HelmorKustomizefor more flexible Kubernetes manifests. - Automate container image builds using a CI/CD tool (e.g., GitHub Actions, Jenkins).
- Secure your Git repositories and Docker images with access controls.
This approach integrates your FastAPI app seamlessly into the ArgoCD App of Apps pattern!
Share
Sign up for more like this
No spam. No jibber jabber. Unsubscribe any time.
More articles