算法艺术创作
algorithmic-art
通过代码和可调参数创作生成艺术与交互式视觉效果。
argo-cd【设计与创意】Use this skill when the user says 'ArgoCD', 'Argo CD', 'GitOps', 'ApplicationSet', 'Sync Policy', 'Sync Wave', 'Application Controller', 'argocd CLI', 'Declarative GitOps', 'Progressive Delivery', 'Rollback', 'Multi-cluster ArgoCD', 'ArgoCD RBAC', 'ArgoCD SSO', 'ArgoCD Project'. Covers: application deployment, sync strategies, application sets, multi…
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
Implement GitOps workflows using Argo CD for Kubernetes deployments with sync strategies, application sets, multi-cluster management, and security best practices.
Exact user phrases: "ArgoCD", "Argo CD", "GitOps", "ApplicationSet", "Sync Policy", "Sync Wave", "argocd CLI", "Declarative GitOps", "Progressive Delivery", "Rollback".
Before activating, verify:
Writes to Argo CD Application YAML, ApplicationSet YAML, Argo CD project config, RBAC config, and notification templates.
YAML for Application, ApplicationSet, Project, and RBAC resources. CLI commands for setup and operations.
No preamble. No postamble. No explanations. No filler/hedging/transitions.
Direct file write. No response text.
| Pattern | Use Case | Complexity |
|---|---|---|
| Single Application | One service, one environment | Low |
| ApplicationSet (list generator) | Same app across multiple clusters | Medium |
| ApplicationSet (git generator) | One app per directory in repo | Medium |
| ApplicationSet (SCM generator) | One app per GitHub repo in org | High |
| Multi-source Application | App config + overlay config separately | Medium |
| App of Apps pattern | Deploying multiple related applications | High |
| Strategy | When to Use | Risk Level |
|---|---|---|
| Automated (Auto-Sync) | Dev/staging, non-critical services | Low (fast) |
| Automated with Self-Heal | All environments (recovers drift) | Low |
| Manual Sync | Production, strict change control | High (controlled) |
| Phased (Sync Waves) | Stateful apps, DB migrations | Medium |
| Blue-Green via Argo Rollouts | Zero-downtime production deploys | Medium (complex) |
| Generator | Best For | Example |
|---|---|---|
| List | Simple list of clusters/values | Dev, staging, prod clusters |
| Git | One directory per environment | apps/prod/, apps/staging/ |
| Cluster | All registered clusters | Deploy to every cluster |
| SCM (GitHub) | All repos in an org | One Application per microservice |
| Pull Request | Preview environments per PR | Ephemeral review apps |
| Matrix | Combining multiple generators | Cluster × Environment |
| Method | Pros | Cons |
|---|---|---|
| Local admin | Simple, no dependencies | No MFA, shared credentials |
| OIDC (Google, Okta, Azure AD) | SSO, MFA, group sync | OIDC provider required |
| Dex | Multi-provider, LDAP | Additional component to manage |
| GitHub OAuth | Simple for small teams | Only GitHub users |
Install Argo CD → Register target cluster → Define Application YAML → Sync → Configure RBAC → Set up webhook → Add notifications.
# install/argocd-install.yaml
apiVersion: v1
kind: Namespace
metadata:
name: argocd
---
apiVersion: v1
kind: ConfigMap
metadata:
name: argocd-cm
namespace: argocd
data:
# SSO configuration (OIDC example)
url: https://argocd.example.com
oidc.config: |
name: Okta
issuer: https://dev-123456.okta.com
clientID: $ARGOCD_OIDC_CLIENT_ID
clientSecret: $ARGOCD_OIDC_CLIENT_SECRET
requestedScopes: ["openid", "profile", "email", "groups"]
requestedIDTokenClaims: {"groups": {"essential": true}}
# Repository configuration
repositories: |
- url: https://github.com/myorg/gitops-config
passwordSecret:
name: github-token
key: token
# Resource customization
resource.customizations: |
admissionregistration.k8s.io/MutatingWebhookConfiguration:
health.lua: |
hs = {}
hs.status = "Healthy"
return hs
---
apiVersion: v1
kind: ConfigMap
metadata:
name: argocd-rbac-cm
namespace: argocd
data:
policy.default: role:readonly
policy.csv: |
p, role:org-admin, applications, *, */*, allow
p, role:team-lead, applications, sync, */*, allow
p, role:team-lead, applications, get, */*, allow
p, role:team-lead, applications, update, */*, allow
p, role:dev, applications, get, team-*/*, allow
p, role:dev, applications, sync, team-*/*, allow
p, role:dev, exec, create, team-*/*, allow
g, myorg/team-leads, role:team-lead
g, myorg/dev-team, role:dev
# Install with:
# kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
# kubectl apply -n argocd -f argocd-cm.yaml
# kubectl apply -n argocd -f argocd-rbac-cm.yaml
# apps/payment-service.yaml
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: payment-service
namespace: argocd
finalizers:
- resources-finalizer.argocd.argoproj.io # Cascade delete
spec:
project: default
source:
repoURL: https://github.com/myorg/payment-service.git
targetRevision: main
path: kubernetes/overlays/production
helm:
valueFiles:
- values-prod.yaml
parameters:
- name: replicaCount
value: "3"
kustomize:
namePrefix: prod-
destination:
server: https://kubernetes.default.svc
namespace: payment-system
syncPolicy:
automated:
prune: true
selfHeal: true
allowEmpty: false
syncOptions:
- CreateNamespace=true
- PruneLast=true # Prune resources after sync
- ApplyOutOfSyncOnly=true
- RespectIgnoreDifferences=true
- ServerSideApply=true # Use SSA for CRDs
retry:
limit: 5
backoff:
duration: 5s
factor: 2
maxDuration: 3m
ignoreDifferences:
- group: apps
kind: Deployment
jsonPointers:
- /spec/replicas # Ignore replica count drift from HPA
- group: autoscaling
kind: HorizontalPodAutoscaler
jsonPointers:
- /spec/metrics # HPA may have different metrics
info:
- name: Slack Channel
value: "#team-payments"
- name: Runbook
value: "https://runbook.example.com/payment-service"
# appsets/cluster-apps.yaml
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: cluster-apps
namespace: argocd
spec:
generators:
# Git generator — one Application per directory in apps/
- git:
repoURL: https://github.com/myorg/gitops-config.git
revision: HEAD
directories:
- path: apps/production/*
- path: apps/staging/*
template:
metadata:
name: '{{path.basename}}'
labels:
environment: '{{path[1]}}'
spec:
project: default
source:
repoURL: https://github.com/myorg/{{path.basename}}.git
targetRevision: main
path: kubernetes/overlays/{{path[1]}}
destination:
server: https://kubernetes.default.svc
namespace: '{{path.basename}}'
syncPolicy:
automated:
prune: true
selfHeal: true
syncPolicy:
preserveResourcesOnDeletion: false
# appsets/multi-cluster-apps.yaml
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: multi-cluster-apps
namespace: argocd
spec:
generators:
- matrix:
generators:
# List of clusters
- clusters:
selector:
matchLabels:
environment: production
# List of apps
- list:
elements:
- app: payment-service
path: payment-service
- app: notification-service
path: notification-service
template:
metadata:
name: '{{app}}-{{name}}'
labels:
app: '{{app}}'
cluster: '{{name}}'
environment: '{{metadata.labels.environment}}'
spec:
project: default
source:
repoURL: https://github.com/myorg/{{app}}.git
targetRevision: main
path: kubernetes/overlays/{{metadata.labels.environment}}
destination:
server: '{{server}}'
namespace: '{{app}}'
syncPolicy:
automated:
prune: true
# Example: Database migration before app rollout
---
# Wave -10: CRDs first
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
argocd.argoproj.io/sync-wave: "-10"
...
---
# Wave -5: Namespace and RBAC
apiVersion: v1
kind: Namespace
metadata:
annotations:
argocd.argoproj.io/sync-wave: "-5"
...
---
# Wave 0: ConfigMaps and Secrets (app config)
apiVersion: v1
kind: ConfigMap
metadata:
annotations:
argocd.argoproj.io/sync-wave: "0"
...
---
# Wave 1: Database migration Job
apiVersion: batch/v1
kind: Job
metadata:
annotations:
argocd.argoproj.io/sync-wave: "1"
argocd.argoproj.io/hook: Sync # Run on every sync
spec:
template:
spec:
restartPolicy: Never
containers:
- name: migration
image: myapp/migration:latest
env:
- name: DATABASE_URL
valueFrom:
secretKeyRef:
name: db-credentials
key: url
---
# Wave 2: Application Deployment
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
argocd.argoproj.io/sync-wave: "2"
spec:
replicas: 3
...
---
# Wave 3: Service and Ingress
apiVersion: v1
kind: Service
metadata:
annotations:
argocd.argoproj.io/sync-wave: "3"
...
# rollouts/payment-service-rollout.yaml
apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
name: payment-service
namespace: payment-system
spec:
replicas: 10
revisionHistoryLimit: 3
selector:
matchLabels:
app: payment-service
template:
metadata:
labels:
app: payment-service
spec:
containers:
- name: app
image: myapp/payment-service:latest
ports:
- containerPort: 8080
strategy:
canary:
maxSurge: "25%"
maxUnavailable: 0
steps:
- setWeight: 5
- pause: {duration: 2m}
- setWeight: 25
- pause: {duration: 5m}
- setWeight: 50
- pause: {duration: 10m}
- setWeight: 75
- pause: {duration: 10m}
- setWeight: 100
analysis:
templates:
- templateName: success-rate
args:
- name: service-name
value: payment-service
trafficRouting:
nginx:
stableIngress: payment-service-ingress
---
apiVersion: argoproj.io/v1alpha1
kind: AnalysisTemplate
metadata:
name: success-rate
namespace: payment-system
spec:
args:
- name: service-name
metrics:
- name: success-rate
interval: 1m
count: 5
successCondition: result >= 95
provider:
prometheus:
query: |
sum(rate(http_requests_total{
service="{{args.service-name}}",
status!~"5.."
}[1m]))
/
sum(rate(http_requests_total{
service="{{args.service-name}}"
}[1m])) * 100
# argocd-notifications-cm.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: argocd-notifications-cm
namespace: argocd
data:
context: |
region: us-east-1
environment: production
grafana_url: https://grafana.example.com
template.app-sync-succeeded: |
message: |
Application {{.app.metadata.name}} sync succeeded.
Sync status: {{.app.status.sync.status}}
Health: {{.app.status.health.status}}
Revision: {{.app.status.sync.revision | substr 0 8}}
template.app-sync-failed: |
message: |
❌ Application {{.app.metadata.name}} sync FAILED.
Sync status: {{.app.status.sync.status}}
Health: {{.app.status.health.status}}
Revision: {{.app.status.sync.revision | substr 0 8}}
Error: {{.app.status.operationState.syncResult.revision}}
trigger.on-sync-succeeded: |
- description: Application sync succeeded
send: [app-sync-succeeded]
when: app.status.sync.status == 'Synced'
trigger.on-sync-failed: |
- description: Application sync failed
send: [app-sync-failed]
when: app.status.operationState.phase in ['Error', 'Failed']
trigger.on-health-degraded: |
- description: Application health degraded
send: [app-health-degraded]
when: app.status.health.status == 'Degraded'
service.slack: |
token: $slack-token
username: ArgoCD Bot
icon: https://argo-cd.readthedocs.io/en/stable/assets/logo.png
# Add a remote cluster to Argo CD
# On the remote cluster:
SERVICE_ACCOUNT_NAME=argocd-manager
NAMESPACE=kube-system
kubectl create sa $SERVICE_ACCOUNT_NAME -n $NAMESPACE
kubectl create clusterrolebinding $SERVICE_ACCOUNT_NAME \
--clusterrole=cluster-admin \
--serviceaccount=$NAMESPACE:$SERVICE_ACCOUNT_NAME
# Get the secret token
SECRET=$(kubectl get sa $SERVICE_ACCOUNT_NAME -n $NAMESPACE -o jsonpath='{.secrets[0].name}')
TOKEN=$(kubectl get secret $SECRET -n $NAMESPACE -o jsonpath='{.data.token}' | base64 -d)
APISERVER=$(kubectl config view --minify -o jsonpath='{.clusters[0].cluster.server}')
# On Argo CD control node:
argocd cluster add <context-name> \
--name=production-us-east-1 \
--label=environment=production \
--label=region=us-east-1
| Feature | Argo CD | Flux v2 |
|---|---|---|
| Architecture | Controller + CLI + API | Controller-only |
| UI | Built-in Web UI | No native UI (use Weave GitOps) |
| ApplicationSets | Built-in (powerful generators) | Not built-in (use Kustomize) |
| Sync mechanism | Git → desired state → apply | Git → reconcile loop |
| Health assessment | Built-in LUA scripts | Kubernetes status |
| SSO/SAML | OIDC, Dex, SAML | OIDC via CLI |
| Multi-cluster | Via cluster registration | Via Kustomization targeting |
| Argo Rollouts | Native integration | Separate Flagger |
| Notifications | Built-in | Via Flux notification controllers |
| Learning curve | Medium | Medium-High |
| RBAC | Fine-grained policy | Kubernetes RBAC |
Enabling automated.prune: true without PR review process. Prune can delete resources in bulk. Always review sync diff before production.
Engineers editing resources directly with kubectl in namespaces managed by Argo CD. Argo CD treats this as drift and will self-heal (or fail if self-heal is off).
Putting all environments and apps in one repo without structure. Use separate repos per service or well-organized directories with ApplicationSet.
Not handling CRD health checks. Argo CD can't determine health of custom resources without LUA health scripts in resource.customizations.
All resources synced simultaneously. Database migrations running at the same time as application deployments cause failures.
Using role:admin for all users. Create least-privilege roles (readonly, sync-only, admin per project).
cluster-admin.argocd admin initial password; rotate immediately.statusBadgeEnabled: false if not using badges.| Issue | Likely Cause | Solution |
|---|---|---|
| OutOfSync (drift) | Manual kubectl edit | Revert manual changes; enable self-heal |
| Sync stuck | CRD not installed | Verify CRDs; install missing ones |
| Connection refused | Cluster API not accessible | Check cluster endpoint; network policies |
| Application not found | Namespace mismatch | Verify destination namespace exists |
| Health unknown | CRD health check missing | Add resource.customizations LUA |
| Webhook not triggering | Secret mismatch | Verify webhook secret between Argo CD and Git |
| Repo cloning failed | Git credentials wrong | Update repository credentials in argocd-cm |
syncPolicy.automated.prune: true only after review.argocd app diff before applying.HEAD for production.Argo CD Application/ApplicationSet YAML, Project YAML, RBAC config, notification templates.
After completing this skill: