ToB企服应用市场:ToB评测及商务社交产业平台

标题: 云原生之旅 - 14)遵循 GitOps 实践的好工具 ArgoCD [打印本页]

作者: 罪恶克星    时间: 2022-11-20 14:13
标题: 云原生之旅 - 14)遵循 GitOps 实践的好工具 ArgoCD
前言

Argo CD 是一款基于 kubernetes 的声明式的Gitops 持续部署工具。本文使用 ArgoCD + Kustomize 实现自动化部署Kubernetes工作流。
## 本文同步发表于知乎 https://zhuanlan.zhihu.com/p/584881969
 
安装 Argo CD
  1. kubectl create namespace argocd
  2. kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
复制代码
 
命令行工具 Argo CD CLI

MacOS 安装
  1. brew install argocd
复制代码
  
访问 Argo CD

Option 1: Service Type Load Balancer

You can change Service Type to Load Balancer 
  1. kubectl patch svc argocd-server -n argocd -p '{"spec": {"type": "LoadBalancer"}}'
复制代码
  
Option 2: (Recommend) 使用 Gateway

1. 使用 Ingress-nginx 可参考 云原生之旅 - 8)云原生时代的网关 Ingress Nginx
  1. # Ingress-Nginx installed first
  2. ---
  3. apiVersion: networking.k8s.io/v1
  4. kind: Ingress
  5. metadata:
  6.   annotations:
  7.     ingress.kubernetes.io/force-ssl-redirect: "true"
  8.     ingress.kubernetes.io/ssl-redirect: "true"
  9.     kubernetes.io/ingress.class: nginx
  10.     # If you encounter a redirect loop or are getting a 307 response code
  11.     # then you need to force the nginx ingress to connect to the backend using HTTPS.
  12.     nginx.ingress.kubernetes.io/backend-protocol: "HTTPS" # argocd backend using HTTPS
  13.     # face to internet, recommend update to restrict access
  14.     nginx.ingress.kubernetes.io/whitelist-source-range: |
  15.       0.0.0.0/0
  16.   name: ingress-argocd
  17.   namespace: dmz
  18. spec:
  19.   rules:
  20.   - host: argocd.wadexu.cloud
  21.     http:
  22.       paths:
  23.       - backend:
  24.           service:
  25.             name: argocd-ext-svc
  26.             port:
  27.               number: 8080
  28.         path: /
  29.         pathType: Prefix
  30.   tls:
  31.   - hosts:
  32.     - argocd.wadexu.cloud
  33.     secretName: tls-secret
  34. ---
  35. # add externalName type svc in dmz namespace, so that Ingress (in dmz) can point to this svc in argocd ns
  36. apiVersion: v1
  37. kind: Service
  38. metadata:
  39.   name:  argocd-ext-svc
  40.   namespace: dmz
  41. spec:
  42.   type: ExternalName
  43.   externalName: argocd-server.argocd.svc.cluster.local
  44.   ports:
  45.   - name: http
  46.     port: 8080
  47.     targetPort: 80
  48.     protocol: TCP
  49.   selector:
  50.     app.kubernetes.io/name: argocd-server
复制代码
argocd_ingress.yaml2. 使用 Emissary 参考 云原生之旅 - 9)云原生时代网关的后起之秀Envoy Proxy 和基于Envoy 的 Emissary Ingress
 
Option 3: 端口转发

运行下面命令然后本地浏览器访问 `https://localhost:8080`
  1. kubectl port-forward svc/argocd-server -n argocd 8080:443
复制代码
 
The initial password for the admin account is auto-generated and stored as clear text in the field password in a secret named argocd-initial-admin-secret in your Argo CD installation namespace. You can simply retrieve this password using kubectl
  1. kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d; echo
复制代码
域名取决于你在gateway里面的配置,Login now
  1. argocd login https://argocd.wadexu.cloud
复制代码
如果是端口转发,参考如下命令
  1. kubectl port-forward svc/argocd-server -n argocd 8080:443
  2. argocd login https://localhost:8080 --username admin --password <repalce_me>
复制代码
更改密码
  1. argocd account update-password
复制代码
 
注册 external Cluster

(Optional) 这一步是为了deploy到到外部的cluster,如果仅仅deploy到和Argo CD一起的cluster 则使用 https://kubernetes.default.svc
  1. # list context
  2. kubectx
  3. argocd cluster add xxx_context
复制代码
 
创建 Application

Creating Apps Via CLI
  1. kubectl config set-context --current --namespace=argocd
  2. argocd app create my-app --repo https://github.com/wadexu007/learning_by_doing.git --path Kustomize/demo-manifests/services/demo-app/dev --dest-server https://kubernetes.default.svc --dest-namespace demo
复制代码
 
Sync (Deploy) Application

Syncing via CLI
  1. argocd app get my-app
  2. argocd app sync my-app
复制代码
 
通过UI 创建和Sync Application 也非常简单。详见官方文档
## 本文同步发表于知乎 https://zhuanlan.zhihu.com/p/584881969
 
更多

Argo CD supports several different ways in which Kubernetes manifests can be defined:
 感谢阅读,如果您觉得本文的内容对您的学习有所帮助,您可以打赏和推荐,您的鼓励是我创作的动力。  
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!




欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/) Powered by Discuz! X3.4