Argocd
Argocd
2)
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-
cd/stable/manifests/install.yaml
kubectl create -f
https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
Use this command in order to access Argo CD on your local machine on port 8080
11)Install Argo CD CLI, use the below commands to start with the installation
verify by running
argocd
argocd
argocd controls a Argo CD server
Usage:
argocd [flags]
argocd [command]
Available Commands:
account Manage account settings
admin Contains a set of commands useful for Argo CD administrators and
requires direct Kubernetes access
app Manage applications
cert Manage repository certificates and SSH known hosts entries
cluster Manage cluster credentials
completion output shell completion code for the specified shell (bash or zsh)
context Switch between contexts
gpg Manage GPG keys used for signature verification
help Help about any command
login Log in to Argo CD
logout Log out from Argo CD
proj Manage projects
relogin Refresh an expired authenticate token
repo Manage repository connection parameters
repocreds Manage repository connection parameters
version Print version information
Flags:
--auth-token string Authentication token
--client-crt string Client certificate file
--client-crt-key string Client certificate key file
--config string Path to Argo CD config (default
"/root/.config/argocd/config")
--core If set to true then CLI talks directly to
Kubernetes instead of talking to Argo CD API server
--grpc-web Enables gRPC-web protocol. Useful if Argo
CD server is behind proxy which does not support HTTP2.
--grpc-web-root-path string Enables gRPC-web protocol. Useful if Argo
CD server is behind proxy which does not support HTTP2. Set web root.
-H, --header strings Sets additional header to all requests made
by Argo CD CLI. (Can be repeated multiple times to add multiple headers, also
supports comma separated headers)
-h, --help help for argocd
--http-retry-max int Maximum number of retries to establish http
connection to Argo CD server
--insecure Skip server certificate and domain
verification
--kube-context string Directs the command to the given kube-
context
--logformat string Set the logging format. One of: text|json
(default "text")
--loglevel string Set the logging level. One of: debug|info|
warn|error (default "info")
--plaintext Disable TLS
--port-forward Connect to a random argocd-server port
using port forwarding
--port-forward-namespace string Namespace name which should be used for
port forwarding
--server string Argo CD server address
--server-crt string Server certificate file
13)login
argocd login 172.30.1.2:32073 --grpc-web --plaintext
usename:admin
password:As2VM7N3e2GyIex7
14)
/practice/application.yaml
18)kustomize options
19)
Practice creating an Argo CD project and allowing specific destinations , in this
practice we will cover:
a)
Create an Argo CD project declaratively with below specs and apply it using
kubectl:
Name: dev-project
Description: Dev project
Destination server: https://kubernetes.default.svc
Destination namespace: ns-1 , this will only allow deploying into ns-1 namespace.
cat /practice/project.yaml
apiVersion: argoproj.io/v1alpha1
kind: AppProject
metadata:
name: dev-project
namespace: argocd
spec:
description: Dev project
sourceRepos:
- '*'
destinations:
- namespace: ns-1
server: "https://kubernetes.default.svc"
clusterResourceWhitelist:
- group: '*'
kind: '*'
namespaceResourceWhitelist:
- group: '*'
kind: '*'
Create an Argo CD application declaratively with below specs and apply it using
kubectl:
Name: guestbook-dev-project
project: dev-project
Destination cluster url (local cluster): https://kubernetes.default.svc
Destination namespace: test-1
Source repo: https://github.com/mabusaa/argocd-example-apps.git , or you can fork
the repo and set your repo url.
Source path: guestbook
Source branch: master
Create the application using kubectl
controlplane $ cat /practice/project.yaml
apiVersion: argoproj.io/v1alpha1
kind: AppProject
metadata:
name: dev-project
namespace: argocd
spec:
description: Dev project
sourceRepos:
- '*'
destinations:
- namespace: ns-1
server: "https://kubernetes.default.svc"
clusterResourceWhitelist:
- group: '*'
kind: '*'
namespaceResourceWhitelist:
- group: '*'
kind: '*'
controlplane $
kubectl apply -f /practice/application.yaml
Create an Argo CD project declaratively with below specs and apply it using
kubectl:
Name: project-with-role
Description: project with ci-role
Source repos: allow all
Destination server: allow all
Destination namespace: allow all
Cluster resource whitelist: allow all
Namespace resource whitelist: allow all
Roles: create one role with sync permissions to all applications in same project.
Role name : ci-role
Role Description: Sync privileges for project-with-role
Role Policies : allow sync and get permissions to all applications in this project.
p, proj:project-with-role:ci-role, applications, sync, project-with-role/*, allow
p, proj:project-with-role:ci-role, applications, get, project-with-role/*, allow
Create the project using kubectl
destinations:
- namespace: '*'
server: '*'
clusterResourceWhitelist:
- group: '*'
kind: '*'
namespaceResourceWhitelist:
- group: '*'
kind: '*'
roles:
- name: ci-role
description: Sync privileges for project-with-role
policies:
- p, proj:project-with-role:ci-role, applications, sync, project-with-role/*,
allow
- p, proj:project-with-role:ci-role, applications, get, project-with-role/*,
allow
b)Create a token related to project using CLI, you have to use argocd proj role
create-token command:
Now, try to sync the application using the token, (this should work because role
has the sync permission)
Name: demo
Project: project-with-role
Server: https://kubernetes.default.svc
Namespace: demo
URL: http://172.30.1.2:32073/applications/demo
Repo: https://github.com/mabusaa/argocd-example-apps.git
Target: master
Path: guestbook
SyncWindow: Sync Allowed
Sync Policy: <none>
Sync Status: Synced to master (35b956d)
Health Status: Progressing
Operation: Sync
Sync Revision: 35b956d8a312039d0e76e44592ef97b50ee38c53
Phase: Succeeded
Start: 2023-05-03 07:37:29 +0000 UTC
Finished: 2023-05-03 07:37:31 +0000 UTC
Duration: 2s
Message: successfully synced (all tasks run)
Name: auto-sync-app
Destination cluster url (local cluster): https://kubernetes.default.svc
Destination namespace: auto-sync-app
Source repo: https://github.com/mabusaa/argocd-example-apps.git , Fork the repo and
set your repo url.
Source path: guestbook-with-sub-directories , (path of manifests where it include
k8s service and deployment files).
Source branch: master
Enable the automated sync.
cat /practice/application.yaml
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: auto-sync-app
namespace: argocd
spec:
destination:
namespace: auto-sync-app
server: "https://kubernetes.default.svc"
project: default
source:
path: guestbook-with-sub-directories
repoURL: "https://github.com/mabusaa/argocd-example-apps.git"
targetRevision: master
directory:
recurse: true
syncPolicy:
automated: {}
syncOptions:
- CreateNamespace=true
cat /practice/application.yaml
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: auto-pruning-demo
namespace: argocd
spec:
destination:
namespace: auto-pruning-demo
server: "https://kubernetes.default.svc"
project: default
source:
path: guestbook-with-sub-directories
repoURL: "https://github.com/mabusaa/argocd-example-apps.git"
targetRevision: master
directory:
recurse: true
syncPolicy:
automated:
prune: true
syncOptions:
- CreateNamespace=true
23)Self HEAL:
Scale the deployment into 3 replicas using kubectl
24)Note: Selective sync option will sync only out-of-sync resources. You need it
when you have thousands of resources in which sync take a long time and puts
pressure on API server.
25): Fail on shared resources option make the sync operation to fail if any
resource is found in other applications.
/practice/application2.yaml
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: demo-shared-resources
namespace: argocd
spec:
destination:
namespace: demo-shared-resources
server: "https://kubernetes.default.svc"
project: default
source:
path: guestbook
repoURL: "https://github.com/mabusaa/argocd-example-apps.git"
targetRevision:
directory:
recurse: true
syncPolicy:
automated: {}
syncOptions:
- FailOnSharedResource=true
- CreateNamespace=trueNote: By default ArgoCD use “kubectl apply” to deploy
the resources changes. In some cases you need to “Replace/Recreate” the resources,
ArgoCD can do this by using replace=true.
Manifests level: You can use the replace annotation at manifest level to achieve
this. (argocd.argoproj.io/sync-options: Replace=true)
syncPolicy:
automated: {}
syncOptions:
- Replace=true
on app side
metadata:
annotations:
argocd.argoproj.io/sync-options: Replace=true
27)Source target revision: track major version 1 only, and it should always sync
the latest minor or patch version.
cat /practice/application1.yaml
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: track-helm-range
namespace: argocd
spec:
destination:
namespace: track-helm-range
server: "https://kubernetes.default.svc"
project: default
source:
chart: sealed-secrets
repoURL: "https://charts.bitnami.com/bitnami"
targetRevision: 1.*
syncPolicy:
automated: {}
syncOptions:
- CreateNamespace=true
28). Diffing Customization, Ignore Differences Demo
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: diffing-customization-demo
namespace: argocd
spec:
destination:
namespace: diffing-customization-demo
server: "https://kubernetes.default.svc"
project: default
source:
path: guestbook-with-sub-directories
repoURL: "https://github.com/mabusaa/argocd-example-apps.git"
targetRevision: master
directory:
recurse: true
syncPolicy:
automated: {}
syncOptions:
- CreateNamespace=true
ignoreDifferences:
- group: apps
kind: Deployment
jsonPointers:
- /spec/replicas