Kubernetes-Argo CD

Jas0n0ss發表於2024-08-09

Kubernetes高階工具Argo CD

https://argo-cd.readthedocs.io/en/stable/

Argo CD 是針對 Kubernetes 的宣告式 GitOps 持續交付工具。

Argo CD 是一個為 Kubernetes 而生的,遵循宣告式 GitOps 理念的持續部署(CD)工具。

Argo CD 可在 Git 儲存庫更改時自動同步和部署應用程式。

argocd

Argo CD 使用者介面

安裝argo cd

[root@rocky01 canary] # kubectl create namespace argocd
[root@rocky01 canary] # kubectl config set-context context-lab --namespace argocd
[root@rocky01 canary] # kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
[root@rocky01 canary] # cat ingress-argocd.yml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: argocd-server
  namespace: argocd
  annotations:
    kubernetes.io/ingress.class: "nginx"
    nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
    nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"
spec:
  rules:
  - http:
      paths:
      - pathType: Prefix
        path: /
        backend:
          service:
            name: argocd-server
            port:
              name: https
    host: argocd.k8slab.io
  tls:
  - hosts:
    - argocd.k8slab.io
    secretName: argocd-secret
[root@rocky01 canary] # kubectl create -f ingress-argocd.yml -n argocd
[root@rocky01 canary] # kubectl get svc | grep -w argocd-server
argocd-server                             ClusterIP   10.68.41.84     <none>        80/TCP,443/TCP               64m
argocd-server-metrics                     ClusterIP   10.68.141.115   <none>        8083/TCP                     64m
[root@rocky01 canary] # kubectl get ingress
NAME            CLASS    HOSTS              ADDRESS         PORTS     AGE
argocd-server   <none>   argocd.k8slab.io   192.168.5.239   80, 443   12m
[root@rocky01 canary] # curl -I argocd.k8slab.io
HTTP/1.1 308 Permanent Redirect
Date: Thu, 08 Aug 2024 19:03:26 GMT
Content-Type: text/html
Content-Length: 164
Connection: keep-alive
Location: https://argocd.k8slab.io
[root@rocky01 canary] # kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d   # 獲取admin的登陸密碼

如果在訪問Argo-CD頁面的時候出現太多重定向的問題請參考:https://github.com/argoproj/argo-cd/issues/2953

image-20240809030926858

[root@rocky01 canary] # argocd login argocd.k8slab.io
[root@rocky01 canary] # argocd app create guestbook --repo https://github.com/argoproj/argocd-example-apps.git --path kustomize-guestbook --dest-server https://kubernetes.default.svc --dest-namespace default
[root@rocky01 canary] # alias argocdc='argocd --grpc-web'
[root@rocky01 canary] # argocd app sync guestbook
[root@rocky01 canary] # argocdc app get guestbook
Name:               argocd/guestbook
Project:            default
Server:             https://kubernetes.default.svc
Namespace:          argocd
URL:                https://argocd.k8slab.io/applications/guestbook
Source:
- Repo:             https://github.com/argoproj/argocd-example-apps.git
  Target:           HEAD
  Path:             kustomize-guestbook
SyncWindow:         Sync Allowed
Sync Policy:        Manual
Sync Status:        Synced to HEAD (d7927a2)
Health Status:      Healthy

GROUP  KIND        NAMESPACE  NAME                    STATUS  HEALTH   HOOK  MESSAGE
       Service     argocd     kustomize-guestbook-ui  Synced  Healthy        service/kustomize-guestbook-ui created
apps   Deployment  argocd     kustomize-guestbook-ui  Synced  Healthy        deployment.apps/kustomize-guestbook-ui created

image-20240809032426533

image-20240809032553799

[root@rocky01 canary] # kubectl get svc | grep book
kustomize-guestbook-ui                    ClusterIP   10.68.125.77    <none>        80/TCP                       11m
[root@rocky01 canary] # kubectl create ingress --rule="guestbook-ui.k8slab.io/=kustomize-guestbook-ui:80" --class=nginx guestbook-ui
ingress.networking.k8s.io/guestbook-ui created
[root@rocky01 canary] # kubectl get ingress
NAME            CLASS    HOSTS                    ADDRESS         PORTS     AGE
argocd-server   <none>   argocd.k8slab.io         192.168.5.239   80, 443   37m
guestbook-ui    nginx    guestbook-ui.k8slab.io   192.168.5.239   80        11s
[root@rocky01 canary] # curl -I guestbook-ui.k8slab.io
HTTP/1.1 200 OK
Date: Thu, 08 Aug 2024 19:28:21 GMT

相關文章