microk8s 安裝 Argo CD 示範

筆者安裝 Argo CD 失敗了非常多次,經驗不足,遇到非常多問題。多虧是安裝在虛擬機中,可以一直快照、還原,斷斷續續嘗試了一個月才弄好...

安裝 Argo CD

確認 Kubernetes 設定檔存在:
    
cat ~/.kube/config
    

如果設定檔不存在,使用下面的指令將 microk8s 設定檔複製過去:
    
microk8s config > ~/.kube/config
    

建立 kubectl 別名:
    
sudo snap alias microk8s.kubectl kubectl
    

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

安裝 Argo CD CLI
    
curl -sSL -o argocd-linux-amd64 https://github.com/argoproj/argo-cd/releases/latest/download/argocd-linux-amd64
sudo install -m 555 argocd-linux-amd64 /usr/local/bin/argocd
rm argocd-linux-amd64
    

測試 argocd 安裝完成:
    
argocd
    

取得 admin 的預設密碼:
    
argocd admin initial-password -n argocd
    

範例輸出:
    
argocd admin initial-password -n argocd
OnjeIpEAAANMmYML

 This password must be only used for first time login. We strongly recommend you update the password using `argocd account update-password`.
    

啟動 argocd ,並暴露 8080 port
    
kubectl port-forward svc/argocd-server -n argocd --address='0.0.0.0' 8080:443
    

使用 IP + port 連入主機,例如 192.168.0.30:8080

預設帳號:admin
密碼為上面使用指令取得的密碼

使用 Ingress 暴露

上面我們是使用指令視窗暫時將 Argo CD 服務使用 8080 port 暫時暴露出來,指令一終止就無法存取,並且也不安全,比較好的做法是建立 Ingress ,將服務正確對外開放。

在下方示範中需要使用到網域名稱,使用 argo-cd.local 這個網域名稱做示範。因為我們實際上並沒有這個網域名稱,所以需要手動設定 hosts (windows),讓電腦會把指向 argo-cd.local 的這個網域導向到我們的主機。

延伸閱讀: Windows 手動設定本機網域名稱對應 hosts

要加入的內容為(假設主機 IP 為 192.168.0.30):
    
192.168.0.30 argo-cd.local
    



建立 Ingress 設定檔:
    
sudo vi argocd-ingress.yaml
    

輸入以下內容:
    
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: argocd-server-ingress
  namespace: argocd
  annotations:
    nginx.io/tls-acme: "true"
    nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"
    nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
    nginx.ingress.kubernetes.io/ssl-passthrough: "true"
spec:
  ingressClassName: nginx
  rules:
    - host: argo-cd.local
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: argocd-server
                port:
                  name: https
  tls:
  - hosts:
    - argo-cd.local
    secretName: argocd-secret
    

執行:
    
kubectl apply -f argocd-ingress.yaml
    

範例輸出:
    
kubectl apply -f argocd-ingress.yaml
ingress.networking.k8s.io/argocd-server-ingress created
    

就可以使用下面的網頁開啟 Argo CD 了:
    
https://argo-cd.local
    

這裡也附上刪除的語法:
    
kubectl delete -f argocd-ingress.yaml
    



參考資料:
Argo CD - CLI Installation

留言