前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >外包精通--官网一步一步教你Argocd GuestBook Demo

外包精通--官网一步一步教你Argocd GuestBook Demo

作者头像
Godev
修改2023-07-31 19:32:25
8480
修改2023-07-31 19:32:25
举报
文章被收录于专栏:Godev

Argocd GuestBook Demo

私有GitHub

Argocd官网

Argocd GetStart

Argo CD is a declarative, GitOps continuous delivery tool for Kubernetes.

Argo CD UI
Argo CD UI

Architecture

Argo CD Architecture
Argo CD Architecture

Argo CD is implemented as a kubernetes controller which continuously monitors running applications and compares the current, live state against the desired target state (as specified in the Git repo). A deployed application whose live state deviates from the target state is considered OutOfSync. Argo CD reports & visualizes the differences, while providing facilities to automatically or manually sync the live state back to the desired target state. Any modifications made to the desired target state in the Git repo can be automatically applied and reflected in the specified target environments.

For additional details, see architecture overview.

Core Concepts

Let's assume you're familiar with core Git, Docker, Kubernetes, Continuous Delivery, and GitOps concepts. Below are some of the concepts that are specific to Argo CD.

  • Application A group of Kubernetes resources as defined by a manifest. This is a Custom Resource Definition (CRD).
  • Application source type Which Tool is used to build the application.
  • Target state The desired state of an application, as represented by files in a Git repository.
  • Live state The live state of that application. What pods etc are deployed.
  • Sync status Whether or not the live state matches the target state. Is the deployed application the same as Git says it should be?
  • Sync The process of making an application move to its target state. E.g. by applying changes to a Kubernetes cluster.
  • Sync operation status Whether or not a sync succeeded.
  • Refresh Compare the latest code in Git with the live state. Figure out what is different.
  • Health The health of the application, is it running correctly? Can it serve requests?
  • Tool A tool to create manifests from a directory of files. E.g. Kustomize. See Application Source Type.
  • Configuration management tool See Tool.
  • Configuration management plugin A custom tool.

1. Install Argo CD

Argo CD Github

代码语言:txt
复制
kubectl create namespace argocd
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/core-install.yaml

This will create a new namespace, argocd, where Argo CD services and application resources will live.

代码语言:txt
复制
[root@k8s-master argocd]# kubectl apply -n argocd -f install.yaml 
customresourcedefinition.apiextensions.k8s.io/applications.argoproj.io created
customresourcedefinition.apiextensions.k8s.io/applicationsets.argoproj.io created
customresourcedefinition.apiextensions.k8s.io/appprojects.argoproj.io created
serviceaccount/argocd-application-controller created
serviceaccount/argocd-applicationset-controller created
serviceaccount/argocd-dex-server created
serviceaccount/argocd-notifications-controller created
serviceaccount/argocd-redis created
serviceaccount/argocd-repo-server created
serviceaccount/argocd-server created
role.rbac.authorization.k8s.io/argocd-application-controller created
role.rbac.authorization.k8s.io/argocd-applicationset-controller created
role.rbac.authorization.k8s.io/argocd-dex-server created
role.rbac.authorization.k8s.io/argocd-notifications-controller created
role.rbac.authorization.k8s.io/argocd-server created
clusterrole.rbac.authorization.k8s.io/argocd-application-controller created
clusterrole.rbac.authorization.k8s.io/argocd-server created
rolebinding.rbac.authorization.k8s.io/argocd-application-controller created
rolebinding.rbac.authorization.k8s.io/argocd-applicationset-controller created
rolebinding.rbac.authorization.k8s.io/argocd-dex-server created
rolebinding.rbac.authorization.k8s.io/argocd-notifications-controller created
rolebinding.rbac.authorization.k8s.io/argocd-redis created
rolebinding.rbac.authorization.k8s.io/argocd-server created
clusterrolebinding.rbac.authorization.k8s.io/argocd-application-controller created
clusterrolebinding.rbac.authorization.k8s.io/argocd-server created
configmap/argocd-cm created
configmap/argocd-cmd-params-cm created
configmap/argocd-gpg-keys-cm created
configmap/argocd-notifications-cm created
configmap/argocd-rbac-cm created
configmap/argocd-ssh-known-hosts-cm created
configmap/argocd-tls-certs-cm created
secret/argocd-notifications-secret created
secret/argocd-secret created
service/argocd-applicationset-controller created
service/argocd-dex-server created
service/argocd-metrics created
service/argocd-notifications-controller-metrics created
service/argocd-redis created
service/argocd-repo-server created
service/argocd-server created
service/argocd-server-metrics created
deployment.apps/argocd-applicationset-controller created
deployment.apps/argocd-dex-server created
deployment.apps/argocd-notifications-controller created
deployment.apps/argocd-redis created
deployment.apps/argocd-repo-server created
deployment.apps/argocd-server created
statefulset.apps/argocd-application-controller created
networkpolicy.networking.k8s.io/argocd-application-controller-network-policy created
networkpolicy.networking.k8s.io/argocd-applicationset-controller-network-policy created
networkpolicy.networking.k8s.io/argocd-dex-server-network-policy created
networkpolicy.networking.k8s.io/argocd-notifications-controller-network-policy created
networkpolicy.networking.k8s.io/argocd-redis-network-policy created
networkpolicy.networking.k8s.io/argocd-repo-server-network-policy created
networkpolicy.networking.k8s.io/argocd-server-network-policy created
[root@k8s-master argocd]# 
代码语言:txt
复制
[root@k8s-master argocd]# kubectl get svc -n argocd
NAME                                      TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                      AGE
argocd-applicationset-controller          ClusterIP   10.111.123.225   <none>        7000/TCP,8080/TCP            3m55s
argocd-dex-server                         ClusterIP   10.103.157.246   <none>        5556/TCP,5557/TCP,5558/TCP   3m54s
argocd-metrics                            ClusterIP   10.108.23.118    <none>        8082/TCP                     3m54s
argocd-notifications-controller-metrics   ClusterIP   10.96.248.236    <none>        9001/TCP                     3m54s
argocd-redis                              ClusterIP   10.99.82.214     <none>        6379/TCP                     3m54s
argocd-repo-server                        ClusterIP   10.100.87.16     <none>        8081/TCP,8084/TCP            3m54s
argocd-server                             ClusterIP   10.106.64.187    <none>        80/TCP,443/TCP               3m54s
argocd-server-metrics                     ClusterIP   10.109.40.112    <none>        8083/TCP                     3m54s
[root@k8s-master argocd]# 
[root@k8s-master argocd]# kubectl patch svc argocd-server -n argocd -p '{"spec": {"type": "NodePort"}}'
service/argocd-server patched
[root@k8s-master argocd]# kubectl get svc -n argocd
NAME                                      TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                      AGE
argocd-applicationset-controller          ClusterIP   10.111.123.225   <none>        7000/TCP,8080/TCP            5m30s
argocd-dex-server                         ClusterIP   10.103.157.246   <none>        5556/TCP,5557/TCP,5558/TCP   5m29s
argocd-metrics                            ClusterIP   10.108.23.118    <none>        8082/TCP                     5m29s
argocd-notifications-controller-metrics   ClusterIP   10.96.248.236    <none>        9001/TCP                     5m29s
argocd-redis                              ClusterIP   10.99.82.214     <none>        6379/TCP                     5m29s
argocd-repo-server                        ClusterIP   10.100.87.16     <none>        8081/TCP,8084/TCP            5m29s
argocd-server                             NodePort    10.106.64.187    <none>        80:32201/TCP,443:30702/TCP   5m29s
argocd-server-metrics                     ClusterIP   10.109.40.112    <none>        8083/TCP                     5m29s
[root@k8s-master argocd]# 
[root@k8s-master argocd]# 
[root@k8s-master argocd]# 
[root@k8s-master argocd]# 
代码语言:txt
复制
[root@k8s-master argocd]# kubectl get pod,svc -n argocd
NAME                                                    READY   STATUS    RESTARTS   AGE
pod/argocd-application-controller-0                     1/1     Running   0          56m
pod/argocd-applicationset-controller-67cf8dcc88-8wqk6   1/1     Running   0          56m
pod/argocd-dex-server-859899bdd-bpl6d                   1/1     Running   0          56m
pod/argocd-notifications-controller-575bfb9f47-spdph    1/1     Running   0          56m
pod/argocd-redis-74d77964b-62f87                        1/1     Running   0          56m
pod/argocd-repo-server-5bfb9fdd99-nj5wn                 1/1     Running   0          56m
pod/argocd-server-6db87f5986-8jsmp                      1/1     Running   0          56m

NAME                                              TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                      AGE
service/argocd-applicationset-controller          ClusterIP   10.111.123.225   <none>        7000/TCP,8080/TCP            56m
service/argocd-dex-server                         ClusterIP   10.103.157.246   <none>        5556/TCP,5557/TCP,5558/TCP   56m
service/argocd-metrics                            ClusterIP   10.108.23.118    <none>        8082/TCP                     56m
service/argocd-notifications-controller-metrics   ClusterIP   10.96.248.236    <none>        9001/TCP                     56m
service/argocd-redis                              ClusterIP   10.99.82.214     <none>        6379/TCP                     56m
service/argocd-repo-server                        ClusterIP   10.100.87.16     <none>        8081/TCP,8084/TCP            56m
service/argocd-server                             NodePort    10.106.64.187    <none>        80:32201/TCP,443:30702/TCP   56m
service/argocd-server-metrics                     ClusterIP   10.109.40.112    <none>        8083/TCP                     56m
[root@k8s-master argocd]# 
代码语言:txt
复制
kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d; echo
代码语言:txt
复制
[root@k8s-master argocd]# kubectl get secret -n argocd argocd-initial-admin-secret -o yaml
apiVersion: v1
data:
  password: Z1ZkcTRXbFVQV0taN1VLTw==
kind: Secret
metadata:
  creationTimestamp: "2023-05-03T18:44:17Z"
  name: argocd-initial-admin-secret
  namespace: argocd
  resourceVersion: "76395"
  uid: f7018d3c-0a78-4a7b-bb7d-27a946d30fce
type: Opaque
[root@k8s-master argocd]# 
[root@k8s-master argocd]# 
[root@k8s-master argocd]# echo Z1ZkcTRXbFVQV0taN1VLTw== |base64 -d
gVdq4WlUPWKZ7UKO[root@k8s-master argocd]# 

1.2 Login Using The CLI

FATA0000 Argo CD server address unspecified

Using the username admin and the password from above, login to Argo CD's IP or hostname: need login argocd-server

代码语言:txt
复制
[root@k8s-master argocd]# argocd version
argocd: v2.7.1+5e54351
  BuildDate: 2023-05-02T16:54:25Z
  GitCommit: 5e543518dbdb5384fa61c938ce3e045b4c5be325
  GitTreeState: clean
  GoVersion: go1.19.8
  Compiler: gc
  Platform: linux/amd64
FATA[0000] Argo CD server address unspecified           
[root@k8s-master argocd]#
代码语言:txt
复制
[root@k8s-master argocd]# argocd login argocd-server
FATA[0000] dial tcp: lookup argocd-server on 192.168.2.1:53: no such host 
[root@k8s-master argocd]# argocd login 10.106.64.187
WARNING: server certificate had error: x509: cannot validate certificate for 10.106.64.187 because it doesn't contain any IP SANs. Proceed insecurely (y/n)? y
Username: admin
Password: 
'admin:login' logged in successfully
Context '10.106.64.187' updated
[root@k8s-master argocd]# 

Creating Apps Via CLI

First we need to set the current namespace to argocd running the following command:

代码语言:txt
复制
kubectl config set-context --current --namespace=argocd

2.Download Argo CD CLI

Download the latest Argo CD version from https://github.com/argoproj/argo-cd/releases/latest. More detailed installation instructions can be found via the CLI installation documentation.

代码语言:txt
复制
argocd app create guestbook --repo https://github.com/argoproj/argocd-example-apps.git --path guestbook --dest-server https://kubernetes.default.svc --dest-namespace default

Sync (Deploy) The Application

代码语言:txt
复制
[root@k8s-master argocd]# argocd version
argocd: v2.7.1+5e54351
  BuildDate: 2023-05-02T16:54:25Z
  GitCommit: 5e543518dbdb5384fa61c938ce3e045b4c5be325
  GitTreeState: clean
  GoVersion: go1.19.8
  Compiler: gc
  Platform: linux/amd64
argocd-server: v2.7.1+5e54351.dirty
  BuildDate: 2023-05-02T16:35:40Z
  GitCommit: 5e543518dbdb5384fa61c938ce3e045b4c5be325
  GitTreeState: dirty
  GoVersion: go1.19.6
  Compiler: gc
  Platform: linux/amd64
  Kustomize Version: v5.0.1 2023-03-14T01:32:48Z
  Helm Version: v3.11.2+g912ebc1
  Kubectl Version: v0.24.2
  Jsonnet Version: v0.19.1
[root@k8s-master argocd]# 

Syncing via CLI

代码语言:txt
复制
[root@k8s-master argocd]# argocd app get guestbook
Name:               argocd/guestbook
Project:            default
Server:             https://kubernetes.default.svc
Namespace:          default
URL:                https://10.106.64.187/applications/guestbook
Repo:               https://github.com/argoproj/argocd-example-apps.git
Target:             HEAD
Path:               guestbook
SyncWindow:         Sync Allowed
Sync Policy:        <none>
Sync Status:        Synced to HEAD (53e28ff)
Health Status:      Healthy

GROUP  KIND        NAMESPACE  NAME          STATUS  HEALTH   HOOK  MESSAGE
       Service     default    guestbook-ui  Synced  Healthy        service/guestbook-ui created
apps   Deployment  default    guestbook-ui  Synced  Healthy        deployment.apps/guestbook-ui created
[root@k8s-master argocd]# 

代码语言:txt
复制
[root@k8s-master argocd]# argocd app sync guestbook
TIMESTAMP                  GROUP        KIND   NAMESPACE                  NAME    STATUS   HEALTH        HOOK  MESSAGE
2023-05-04T03:27:20+08:00            Service     default          guestbook-ui    Synced  Healthy              
2023-05-04T03:27:20+08:00   apps  Deployment     default          guestbook-ui    Synced  Healthy              
2023-05-04T03:27:21+08:00            Service     default          guestbook-ui    Synced  Healthy              service/guestbook-ui unchanged
2023-05-04T03:27:21+08:00   apps  Deployment     default          guestbook-ui    Synced  Healthy              deployment.apps/guestbook-ui unchanged

Name:               argocd/guestbook
Project:            default
Server:             https://kubernetes.default.svc
Namespace:          default
URL:                https://10.106.64.187/applications/guestbook
Repo:               https://github.com/argoproj/argocd-example-apps.git
Target:             HEAD
Path:               guestbook
SyncWindow:         Sync Allowed
Sync Policy:        <none>
Sync Status:        Synced to HEAD (53e28ff)
Health Status:      Healthy

Operation:          Sync
Sync Revision:      53e28ff20cc530b9ada2173fbbd64d48338583ba
Phase:              Succeeded
Start:              2023-05-04 03:27:20 +0800 CST
Finished:           2023-05-04 03:27:21 +0800 CST
Duration:           1s
Message:            successfully synced (all tasks run)

GROUP  KIND        NAMESPACE  NAME          STATUS  HEALTH   HOOK  MESSAGE
       Service     default    guestbook-ui  Synced  Healthy        service/guestbook-ui unchanged
apps   Deployment  default    guestbook-ui  Synced  Healthy        deployment.apps/guestbook-ui unchanged
[root@k8s-master argocd]# 

本文系外文翻译,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文系外文翻译前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Argocd GuestBook Demo
    • Architecture¶
    • Core Concepts¶
      • 1. Install Argo CD¶
        • 1.2 Login Using The CLI
          • FATA0000 Argo CD server address unspecified
          • Creating Apps Via CLI¶
        • 2.Download Argo CD CLI¶
          • Sync (Deploy) The Application
            • Syncing via CLI¶
        相关产品与服务
        容器服务
        腾讯云容器服务(Tencent Kubernetes Engine, TKE)基于原生 kubernetes 提供以容器为核心的、高度可扩展的高性能容器管理服务,覆盖 Serverless、边缘计算、分布式云等多种业务部署场景,业内首创单个集群兼容多种计算节点的容器资源管理模式。同时产品作为云原生 Finops 领先布道者,主导开源项目Crane,全面助力客户实现资源优化、成本控制。
        领券
        问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档