当前位置:网站首页>Argo CD usage

Argo CD usage

2022-06-21 06:42:00 youzhouliu

One 、 What is? argo cd

Argo CD Is used for Kubernetes The declarativeness of GitOps Continuous delivery tools .

Two 、 Why use argo cd

Argo CD The required application state can be automatically deployed in the specified target environment , Application deployment can be done in Git Tracking changes to branches on commit , Label update , Or fixed to a specific version of the list .

3、 ... and 、argo cd Architecture diagram

Argo CD The main responsibilities of CD(Continuous Delivery, Continuous delivery ), Deploy the application to Kubernetes Wait for the environment , and CI(Continuous Integration, Continuous integration ) Mainly to Jenkins,Gitlab CI Wait for tools to complete .

Argo CD The architecture of is as follows :

Four 、Argo CD Use

Argo CD Generally installed in Kubernetes In the cluster .

1、 install Argo CD

Use the following command in argocd Namespace deployment Argo CD:

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

2、 install Argo CD CLI

Argo CD CLI It's for management Argo CD Command line tools for , For specific installation methods of different operating systems, please refer to  Argo CD CLI Installation

Mac The system can be used directly brew install Installation , as follows :

brew install argocd

3、 Release Argo CD service

By default , Argo CD The service is not exposed to the public , Can pass LoadBalancer perhaps NodePort Type of Service、Ingress、Kubectl Port forwarding and other methods will Argo CD The service is published to Kubernetes Outside the cluster .

Here, use the following command to pass NodePort The way the service is exposed Argo CD To the outside of the cluster :

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

Now the name has been argocd-server Of Service Change to NodePort Type , It can be used outside the cluster through < node IP>:< Randomly generated NodePort port > To visit Argo CD.

Browser input https://< node IP>:port visit Argo CD.

4、 obtain Argo CD password

By default  admin  The initial password of the account is automatically generated , Will be stored in... In clear text Argo CD The installed namespace is named  argocd-initial-admin-secret  Of Secret Under the object  password  Under the field , You can use the following command to get :

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

#  Return results 
kj8bDMiDTnsEfnjg

Enter the password in the browser to log in Argo CD, The login interface is shown in the figure below :

The login interface is shown below :

5、 Get ready Git Warehouse

stay Gitlab Create project on , named argocd-lab, In order to facilitate the experiment, the warehouse is set to public Public Warehouse . Create... In the warehouse quickstart Catalog , Create two... In the directory yaml Resource file , Namely myapp-deployment.yaml and myapp-service.yaml.

gitlab The contents are as follows :


yaml The content of the resource file is as follows :

# myapp-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp
spec:
  replicas: 1
  selector:
    matchLabels:
      app: myapp
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
      - image: registry.cn-shanghai.aliyuncs.com/public-namespace/myapp:v1
        name: myapp
        ports:
        - containerPort: 80
 
# myapp-service.yaml
apiVersion: v1
kind: Service
metadata:
  name: myapp
spec:
  ports:
  - port: 80
    targetPort: 80
    nodePort: 32060
  type: NodePort
  selector:
    app: myapp

6、 establish Argo CD App

First create a namespace devops be used for Argo CD Deploy the application .

kubectl create ns devops

There are three ways to create app, They are as follows :

Mode one : Use UI establish App

  • Application Name: Custom application name .
  • Project: Use the default created default project .
  • SYNC POLICY: Synchronization mode , You can choose automatic or manual , Here we choose manual synchronization .

  • Repository URL: Project Git Address .
  • Revision: Branch name .
  • Path: yaml The relative path where the resource file is located .

 Cluster URL: Kubernetes API Server Access address of , because Argo CD And distribute the application Kubernetes The cluster is the same , So you can use http://kubernetes.default.svc To visit . About Kubernetes in DNS Parsing rules can be viewed Pod And Service Of DNS.
Namespace: The namespace of the deployment application .

  After creation, as shown in the figure below , At this time OutOfSync The state of :

  Since manual synchronization is set , So you need to click the following SYNC To synchronize :

 

Click in the pop-up box SYNCHRONIZE, Confirm synchronization :

Wait for synchronization to complete .

stay Argo CD Click on the app to view the details , Here's the picture :

Mode two : Use CLI establish APP

argocd app create myapp2 \
--repo http://11.8.36.29/root/argocd-lab.git \
--path quickstart --dest-server \
https://kubernetes.default.svc \
--dest-namespace devops

Use argocd Command to view the created application :

#  List applications 
* argocd app list
NAME   CLUSTER                         NAMESPACE  PROJECT  STATUS  HEALTH   SYNCPOLICY  CONDITIONS  REPO                                   PATH        TARGET
myapp  https://kubernetes.default.svc  devops     default  Synced  Healthy  <none>      <none>      http://11.8.36.29/root/argocd-lab.git  quickstart  main

#  see  myapp  application 
* argocd app get myapp
Name:               myapp
Project:            default
Server:             https://kubernetes.default.svc
Namespace:          devops
URL:                https://11.8.36.159:32313/applications/myapp
Repo:               http://11.8.36.29/root/argocd-lab.git
Target:             main
Path:               quickstart
SyncWindow:         Sync Allowed
Sync Policy:        <none>
Sync Status:        Synced to main (82baed1)
Health Status:      Healthy

GROUP  KIND        NAMESPACE  NAME   STATUS  HEALTH   HOOK  MESSAGE
       Service     devops     myapp  Synced  Healthy        service/myapp created
apps   Deployment  devops     myapp  Synced  Healthy        deployment.apps/myapp created

Mode three : Use YAML File creation

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: myapp
  namespace: argocd
spec:
  destination:
    namespace: devops #  The namespace of the deployment application 
    server: https://kubernetes.default.svc # API Server  Address 
  project: default #  Project name 
  source:
    path: quickstart #  Resource file path 
    repoURL: http://11.8.36.29/root/argocd-lab.git # Git  Warehouse address 
    targetRevision: main #  Branch name 

7、 Version update

take myapp The application changes from manual synchronization to automatic synchronization . Click on APP DETAILS -> SYNC POLICY, Click on ENABLE AUTO-SYNC:

edit myapp Resource file , Change the version from v1 Change it to v2, Click on Commit changes, Submit changes :

Wait a moment Argo CD The application will be automatically updated , If you can't wait, you can click Refresh,Argo CD Will go to get the latest resource files immediately . You can see at this time myapp Deployment Will be newly created v2 Version of Replicaset,v2 Version of Replicaset Will create and manage v2 Version of Pod.

8、 Version rollback

Upgrade to v2 After the version , v1 Version of Replicaset Not deleted , But keep it , This is for the convenience of rolling back the application . stay myapp Click... In the application HISTORY AND ROLLBACK View history , You can see that there is 2 A history :

Let's assume that just launched v2 There is a problem with the version , Need to roll back v1 edition , Then you can select v1 edition , And then click Rollback Roll back :

It needs to be disabled during rollback AUTO-SYNC Automatic synchronization , Click on OK Can be confirmed :

After a while, you can see that the rollback has been successful , here Pod yes v1 Version of , And because the online version is not Git The latest version in the warehouse , Therefore, the synchronization state is OutOfSync:

原网站

版权声明
本文为[youzhouliu]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/172/202206210629464456.html