ArgoCD部署

Argo CD是Kubernetes的一款声明式、GitOps连续交付工具。
为什么使用Argo CD
应用程序定义、配置和环境应该是声明式的,并受版本控制。应用程序部署和生命周期管理应该是自动化的、可审计的,并且易于理解。
在这里插入图片描述
流程图:
在这里插入图片描述

安装:
非HA部署

kubectl create namespace argocd
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml

HA部署

kubectl create namespace argocd
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/ha/install.yaml

如果需要调整时区:
将yaml文件所有deployments增加环境变量

env:
- name: TZ
  value: "Asia/Shanghai"

更改Argo SVC nodeport

kubectl patch svc argocd-server -n argocd -p '{"spec": {"type": "NodePort"}}'

获取初始密码:

kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d; echo

添加APP:
首先在gitlab创建仓库,提交yaml文件到仓库
Argo在添加app前需要添加仓库信息
在这里插入图片描述
SYNC POLICY
可以选择手动或者自动同步,自动同步会每三四分钟检查下仓库里的文件与当前状态做对比,有文件更新触发应用更新
在这里插入图片描述
在这里插入图片描述

安装命令行工具:
在这里插入图片描述

命令行登陆:

argocd login  "argo svc 地址"
argocd app list
argocd cluster list

在这里插入图片描述
创建APP

argocd app create guestbook --repo https://github.com/argoproj/argocd-example-apps.git --path guestbook  --dest-namespace default --dest-server https://kubernetes.default.svc
同步
argocd app sync  guestbook
删除
argocd app delete guestbook

在这里插入图片描述
添加多集群:

kubectl config get-contexts
argocd cluster add default --kubeconfig admin_config --name testcluter
argocd cluster list

在这里插入图片描述
同步应用后会显示正常
在这里插入图片描述
在这里插入图片描述
配置同步状态消息通知,装app状态发送到企业微信,需要先添加微信机器人:

kubectl edit cm argocd-notifications-cm -n argocd

在configmap 添加以下内容,重启argocd-notifications-controller pod

data:
  context: |
    argocdUrl: https://argo地址
  service.webhook.wechat: |
    url: https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxxxxxxxxxxxxx
    headers:
      - name: Content-Type
        value: application/json
  subscriptions: |
    - recipients: [wechat]
      triggers: [on-sync-running, on-deployed, on-sync-failed, on-sync-succeeded]
  template.app-sync-change: |
    webhook:
      wechat:
        method: POST
        body: |
          {
                "msgtype": "markdown",
                "markdown": {
                    "content": "### ArgoCD同步状态\n> - app名称: {{.app.metadata.name}}\n> - app同步状态: {{ .app.status.operationState.phase}}\n> - 时间:{{.app.status.operationState.startedAt}}\n>
- URL: [点击跳转ArgoCD]({{.context.argocdUrl}}/applications/{{.app.metadata.name}}?operation=true) \n"
                }
            }
  trigger.on-deployed: |
    - description: Application is synced and healthy. Triggered once per commit.
      oncePer: app.status.sync.revision
      send: [app-sync-change]  # template names
      # trigger condition
      when: app.status.operationState.phase in ['Succeeded'] and app.status.health.status == 'Healthy'
  trigger.on-health-degraded: |
    - description: Application has degraded
      send: [app-sync-change]
      when: app.status.health.status == 'Degraded'
  trigger.on-sync-failed: |
    - description: Application syncing has failed
      send: [app-sync-change]  # template names
      when: app.status.operationState.phase in ['Error', 'Failed']
  trigger.on-sync-running: |
    - description: Application is being synced
      send: [app-sync-change]  # template names
      when: app.status.operationState.phase in ['Running']
  trigger.on-sync-status-unknown: |
    - description: Application status is 'Unknown'
      send: [app-sync-change]  # template names
      when: app.status.sync.status == 'Unknown'
  trigger.on-sync-succeeded: |
    - description: Application syncing has succeeded
      send: [app-sync-change]  # template names
      when: app.status.operationState.phase in ['Succeeded']

在这里插入图片描述
新增project:
在这里插入图片描述
在这里插入图片描述
同步HPA:
memory 须在cpu前面,不然argocd页面看到HPA同步状态是异常的
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值