Skip to content

Commit 4bb3f0e

Browse files
committed
ArgoCD Lab
1 parent 694b603 commit 4bb3f0e

File tree

2 files changed

+374
-7
lines changed

2 files changed

+374
-7
lines changed

docs/labs/devops/argocd/index.md

Lines changed: 367 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,367 @@
1+
# ArgoCD Lab
2+
3+
=== "OpenShift"
4+
5+
## Pre-requisites
6+
7+
Make sure your environment is setup properly for the lab.
8+
9+
Check the [Environment Setup](../prerequisites/#environment-setup) page for your setup.
10+
11+
## ArgoCD Installation
12+
13+
- Create the namespace `argocd` to install argocd
14+
```bash
15+
oc new-project argocd
16+
```
17+
- Install ArgoCD as follows.
18+
```
19+
oc apply --filename https://raw.githubusercontent.com/ibm-cloud-architecture/learning-cloudnative-101/master/static/yamls/argo-lab/argocd-operator.yaml
20+
```
21+
- When installing the tutorial, make sure you wait until the argocd-operator is finished before installing the argocd-cr..or it will fail. You can do this:
22+
```bash
23+
oc get ClusterServiceVersion -n argocd
24+
NAME DISPLAY VERSION REPLACES PHASE
25+
argocd-operator.v0.0.8 Argo CD 0.0.8 Succeeded
26+
```
27+
and wait for the "succeeded" to come up before proceeding.
28+
```
29+
oc apply --filename https://raw.githubusercontent.com/ibm-cloud-architecture/learning-cloudnative-101/master/static/yamls/argo-lab/argocd-cr.yaml
30+
```
31+
and wait for the argocd server Pod to be running
32+
```
33+
oc get pods -n argocd -l app.kubernetes.io/name=example-argocd-server
34+
```
35+
```
36+
NAME READY STATUS RESTARTS AGE
37+
example-argocd-server-57c4fd5c45-zf4q6 1/1 Running 0 115s
38+
```
39+
- Install the `argocd` CLI, for example on OSX use brew
40+
```bash
41+
brew tap argoproj/tap
42+
brew install argoproj/tap/argocd
43+
```
44+
- Set an environment variable `ARGOCD_URL` using the `EXTERNAL-IP`
45+
```bash
46+
export ARGOCD_NAMESPACE="argocd"
47+
export ARGOCD_SERVER=$(oc get route example-argocd-server -n $ARGOCD_NAMESPACE -o jsonpath='{.spec.host}')
48+
export ARGOCD_URL="https://$ARGOCD_SERVER"
49+
echo ARGOCD_URL=$ARGOCD_URL
50+
echo ARGOCD_SERVER=$ARGOCD_SERVER
51+
```
52+
53+
## Deploying the app
54+
55+
- Login into the UI.
56+
```bash
57+
open $ARGOCD_URL
58+
```
59+
- Use `admin` as the username and get the password with the following command
60+
```bash
61+
oc get secret example-argocd-cluster -n $ARGOCD_NAMESPACE -o jsonpath='{.data.admin\.password}' | base64 -d
62+
```
63+
For example the output is similar to this:
64+
```
65+
tyafMb7BNvO0kP9eizx3CojrK8pYJFQq
66+
```
67+
68+
![ArgoCD Login](../images/argocd_login.png)
69+
70+
- Now go back to the ArgoCD home and click on `NEW APP`.
71+
- Add the below details:
72+
- Application Name: `sample`
73+
- Project - `default`
74+
- SYNC POLICY: `Manual`
75+
- REPO URL: `https://github.com/ibm-cloud-architecture/cloudnative_sample_app_deploy`
76+
- Revision: `HEAD`
77+
- Path: `openshift`
78+
79+
![app details one](../images/app_argo_1.png)
80+
81+
- Cluster - Select the default one `https://kubernetes.default.svc` to deploy in-cluster
82+
- Namespace - `default`
83+
- Click Create to finish
84+
85+
![app details two](../images/app_argo_2.png)
86+
87+
- You will now see the available apps.
88+
89+
![sampleapp create](../images/sampleapp_create.png)
90+
91+
- Initially, the app will be out of sync. It is yet to be deployed. You need to sync it for deploying.
92+
93+
To sync the application, click `SYNC` and then `SYNCHRONIZE`.
94+
95+
![out of sync](../images/out_of_sync.png)
96+
97+
- Wait till the app is deployed.
98+
99+
![synched app](../images/synched_app.png)
100+
101+
- Once the app is deployed, click on it to see the details.
102+
103+
![sample app deployed](../images/sample_app_deployed.png)
104+
105+
![sample app full deployment](../images/sample_app_full_deployment.png)
106+
107+
## Verifying the deployment
108+
109+
- Access the app to verify if it is correctly deployed.
110+
- List the cloudnativesampleapp-service route
111+
```
112+
oc get route
113+
```
114+
It should have an IP under `EXTERNAL-IP` column
115+
```
116+
NAME HOST/PORT PATH SERVICES PORT TERMINATION WILDCARD
117+
cloudnative-sample cloudnative-sample-default.apps-crc.testing cloudnativesampleapp-service 9080 None
118+
```
119+
- Set an environment variable `APP_URL` using the `EXTERNAL-IP`
120+
```
121+
export APP_URL="http://$(oc get route cloudnative-sample -o jsonpath='{.status.ingress[0].host}')"
122+
echo ARGOCD_SERVER=$APP_URL
123+
```
124+
- Access the url using `curl`
125+
```
126+
curl "$APP_URL/greeting?name=Carlos"
127+
```
128+
```
129+
{"id":2,"content":"Welcome to Cloudnative bootcamp !!! Hello, Carlos :)"}
130+
```
131+
132+
## Using the ArgoCD CLI
133+
134+
- Login using the cli.
135+
- Use `admin` as the username and get the password with the following command
136+
```bash
137+
export ARGOCD_PASSWORD=$(oc get secret example-argocd-cluster -n $ARGOCD_NAMESPACE -o jsonpath='{.data.admin\.password}' | base64 -d)
138+
echo $ARGOCD_PASSWORD
139+
```
140+
- Now login as follows.
141+
```bash
142+
argocd login --username admin --password $ARGOCD_PASSWORD $ARGOCD_SERVER
143+
```
144+
```
145+
WARNING: server certificate had error: x509: cannot validate certificate for 10.97.240.99 because it doesn't contain
146+
any IP SANs. Proceed insecurely (y/n)? y
147+
148+
'admin' logged in successfully
149+
Context 'example-argocd-server-argocd.apps-crc.testing' updated
150+
```
151+
- List the applications
152+
```bash
153+
argocd app list
154+
```
155+
```
156+
NAME CLUSTER NAMESPACE PROJECT STATUS HEALTH SYNCPOLICY CONDITIONS REPO PATH TARGET
157+
sample https://kubernetes.default.svc default default Synced Healthy <none> <none> https://github.com/ibm-cloud-architecture/cloudnative_sample_app_deploy openshift HEAD
158+
```
159+
- Get application details
160+
```bash
161+
argocd app get sample
162+
```
163+
```
164+
Name: sample
165+
Project: default
166+
Server: https://kubernetes.default.svc
167+
Namespace: default
168+
URL: https://10.97.240.99/applications/sample
169+
Repo: https://github.com/ibm-cloud-architecture/cloudnative_sample_app_deploy
170+
Target: HEAD
171+
Path: openshift
172+
SyncWindow: Sync Allowed
173+
Sync Policy: <none>
174+
Sync Status: Synced to HEAD (9684037)
175+
Health Status: Healthy
176+
177+
GROUP KIND NAMESPACE NAME STATUS HEALTH HOOK MESSAGE
178+
Service default cloudnativesampleapp-service Synced Healthy service/cloudnativesampleapp-service created
179+
apps Deployment default cloudnativesampleapp-deployment Synced Healthy deployment.apps/cloudnativesampleapp-deployment created
180+
```
181+
- Show application deployment history
182+
```bash
183+
argocd app history sample
184+
```
185+
```
186+
ID DATE REVISION
187+
0 2020-02-12 21:10:32 -0500 EST HEAD (9684037)
188+
```
189+
## References
190+
191+
- [ArgoCD](https://argoproj.github.io/argo-cd/)
192+
193+
=== "Kubernetes"
194+
195+
## Pre-requisites
196+
197+
Make sure your environment is setup properly for the lab.
198+
199+
Check the [Environment Setup](../prerequisites/#environment-setup) page for your setup.
200+
201+
## ArgoCD Installation
202+
203+
- Create the namespace `argocd` to install argocd
204+
```bash
205+
kubectl create namespace argocd
206+
export ARGOCD_NAMESPACE=argocd
207+
```
208+
- Create RBAC resources
209+
```bash
210+
kubectl create -n argocd -f https://raw.githubusercontent.com/argoproj-labs/argocd-operator/v0.0.8/deploy/service_account.yaml
211+
kubectl create -n argocd -f https://raw.githubusercontent.com/argoproj-labs/argocd-operator/v0.0.8/deploy/role.yaml
212+
kubectl create -n argocd -f https://raw.githubusercontent.com/argoproj-labs/argocd-operator/v0.0.8/deploy/role_binding.yaml
213+
kubectl create -n argocd -f https://raw.githubusercontent.com/ibm-cloud-architecture/learning-cloudnative-101/master/static/yamls/argo-lab/argo-clusteradmin.yaml
214+
```
215+
216+
- Install CRDs
217+
```bash
218+
kubectl create -n argocd -f https://raw.githubusercontent.com/argoproj-labs/argocd-operator/v0.0.8/deploy/argo-cd/argoproj.io_applications_crd.yaml
219+
kubectl create -n argocd -f https://raw.githubusercontent.com/argoproj-labs/argocd-operator/v0.0.8/deploy/argo-cd/argoproj.io_appprojects_crd.yaml
220+
kubectl create -n argocd -f https://raw.githubusercontent.com/argoproj-labs/argocd-operator/v0.0.8/deploy/crds/argoproj.io_argocdexports_crd.yaml
221+
kubectl create -n argocd -f https://raw.githubusercontent.com/argoproj-labs/argocd-operator/v0.0.8/deploy/crds/argoproj.io_argocds_crd.yaml
222+
```
223+
Verify CRDs
224+
```bash
225+
kubectl get crd -n argocd
226+
```
227+
```
228+
NAME CREATED AT
229+
applications.argoproj.io 2020-05-15T02:05:55Z
230+
appprojects.argoproj.io 2020-05-15T02:05:56Z
231+
argocdexports.argoproj.io 2020-05-15T02:08:21Z
232+
argocds.argoproj.io 2020-05-15T02:08:21Z
233+
```
234+
- Deploy Operator
235+
```bash
236+
kubectl create -n argocd -f https://raw.githubusercontent.com/argoproj-labs/argocd-operator/v0.0.8/deploy/operator.yaml
237+
```
238+
- Deploy ArgoCD CO
239+
```bash
240+
kubectl create -n argocd -f https://raw.githubusercontent.com/argoproj-labs/argocd-operator/v0.0.8/examples/argocd-lb.yaml
241+
```
242+
Verify that ArgoCD Pods are running
243+
```bash
244+
kubectl get pods -n argocd
245+
```
246+
```
247+
NAME READY STATUS RESTARTS AGE
248+
argocd-operator-5f7d8cf7d8-486vn 1/1 Running 0 3m46s
249+
example-argocd-application-controller-7dc5fcb75d-xkk5h 1/1 Running 0 2m3s
250+
example-argocd-dex-server-bb9df96cb-ndmhl 1/1 Running 0 2m3s
251+
example-argocd-redis-756b6764-sb2gt 1/1 Running 0 2m3s
252+
example-argocd-repo-server-75944fcf87-zmh48 1/1 Running 0 2m3s
253+
example-argocd-server-747b684c8c-xhgl9 1/1 Running 0 2m3s
254+
```
255+
Verify that the other ArgoCD resources are created
256+
```
257+
kubectl get cm,secret,svc,deploy -n argocd
258+
```
259+
- List the argocd-server service
260+
```bash
261+
kubectl get svc example-argocd-server -n argocd
262+
```
263+
264+
- From the script, the Argo Server service has a `type` of `LoadBalancer`. If the `ExternalIP` is in a `pending` state, then there is no loadBalancer for your cluster, so we only need the the ArgoCD server's `NodePort`. Otherwise use the `ExternalIP` and `NodePort` to access Argo.
265+
```
266+
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
267+
example-argocd-server LoadBalancer 10.105.73.245 <pending> 80:31138/TCP,443:31932/TCP 5m3s
268+
```
269+
270+
- To access the service we need the `Node's External IP` and the `NodePort`. Let's set an environment variable `ARGOCD_URL` with `NODE_EXTERNAL_IP`:`NodePort`.
271+
```bash
272+
export NODE_EXTERNAL_IP="$(kubectl get nodes -o jsonpath='{.items[0].status.addresses[?(@.type=="ExternalIP")].address}')"
273+
export ARGOCD_NODEPORT="$(kubectl get svc example-argocd-server -n $ARGOCD_NAMESPACE -o jsonpath='{.spec.ports[0].nodePort}')"
274+
export ARGOCD_URL="https://$NODE_EXTERNAL_IP:$ARGOCD_NODEPORT"
275+
echo ARGOCD_URL=$ARGOCD_URL
276+
```
277+
278+
- If you can't access the NodePort from your computer and only http/80 then edit the argocd-server and add the flag `--insecure`
279+
```bash
280+
kubectl edit -n argocd deployment example-argocd-server
281+
```
282+
Use the kube api to proxy into the argocd server using `kubectl port-forward`
283+
```
284+
kubectl port-forward service/example-argocd-server 8080:80 -n argocd
285+
```
286+
Then you can access the argocd server locally on port 8080 [http://localhost:8080](http://localhost:8080)
287+
288+
## Deploying the app
289+
290+
- Login using the Browser into the UI using `$ARGOCD_URL` or `localhost:8080` if using port-forward
291+
- Use `admin` as the username and get the password with the following command
292+
```bash
293+
kubectl get secret example-argocd-cluster -n $ARGOCD_NAMESPACE -o jsonpath='{.data.admin\.password}' | base64 -d
294+
```
295+
For example the output is similar to this:
296+
```
297+
tyafMb7BNvO0kP9eizx3CojrK8pYJFQq
298+
```
299+
300+
![ArgoCD Login](../images/argocd_login.png)
301+
302+
- Now go back to the ArgoCD home and click on `NEW APP`.
303+
- Add the below details:
304+
- Application Name: `sample`
305+
- Project - `default`
306+
- SYNC POLICY: `Manual`
307+
- REPO URL: `https://github.com/ibm-cloud-architecture/cloudnative_sample_app_deploy`
308+
- Revision: `HEAD`
309+
- Path: `kubernetes`
310+
311+
![app details one](../images/app_argo_1.png)
312+
313+
- Cluster - Select the default one `https://kubernetes.default.svc` to deploy in-cluster
314+
- Namespace - `default`
315+
- Click Create to finish
316+
317+
![app details two](../images/app_argo_2.png)
318+
319+
- You will now see the available apps.
320+
321+
![sampleapp create](../images/sampleapp_create.png)
322+
323+
- Initially, the app will be out of sync. It is yet to be deployed. You need to sync it for deploying.
324+
325+
To sync the application, click `SYNC` and then `SYNCHRONIZE`.
326+
327+
![out of sync](../images/out_of_sync.png)
328+
329+
- Wait till the app is deployed.
330+
331+
![synched app](../images/synched_app.png)
332+
333+
- Once the app is deployed, click on it to see the details.
334+
335+
![sample app deployed](../images/sample_app_deployed.png)
336+
337+
![sample app full deployment](../images/sample_app_full_deployment.png)
338+
339+
## Verifying the deployment
340+
341+
- Access the app to verify if it is correctly deployed.
342+
- List the cloudnativesampleapp-service service
343+
```bash
344+
kubectl get svc cloudnativesampleapp-service
345+
```
346+
It will have the `NodePort` for the application. In this case, it is `30499`.
347+
```
348+
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
349+
cloudnativesampleapp-service NodePort 172.21.118.165 <none> 9080:30499/TCP 20s
350+
```
351+
- Set an environment variable `APP_URL` using the `Node's IP` and `NodePort` values
352+
```bash
353+
export APP_NODE_PORT="$(kubectl get svc cloudnativesampleapp-service -n default -o jsonpath='{.spec.ports[0].nodePort}')"
354+
export APP_URL="$NODE_EXTERNAL_IP:$APP_NODE_PORT"
355+
echo Application=$APP_URL
356+
```
357+
- Access the url using `curl`
358+
```bash
359+
curl "$APP_URL/greeting?name=Carlos"
360+
```
361+
```
362+
{"id":2,"content":"Welcome to Cloudnative bootcamp !!! Hello, Carlos :)"}
363+
```
364+
365+
## References
366+
367+
- [ArgoCD](https://argoproj.github.io/argo-cd/)

0 commit comments

Comments
 (0)