PortainerIt is a powerful tool that simplifies the management of containerized applications, and thanks to its built-in...GitOpsFunction, fromGitDeploying and managing applications in a repository becomes seamless and convenient. In this article, we will demonstrate how to create a repository for storage.GitInKubernetesConfigure using configuration filesPortainerofGitOpsIt is supplemented with real-world examples and practical scenarios.。
I. What is GitOps?
GitOpsIt is a modern management and automated deployment method that willGit It is considered an authoritative source for infrastructure and application configuration.GitOpsAll changes are inGitIt takes place in the warehouse, and likePortainerSuchGitOpsTools ensure the operating environmentandGitThis approach maintains consistency with the desired state defined in the code. It offers advantages such as traceability, version control, and automatic rollback.
II. Setting up Gitops in Portainer
exist Portainer In, when you store fromGit When creating a new application from a manifest in the repository, you can set...GitOpsNo need for separate“Enable”GitOps——It is natively supported as part of the coded application deployment process.
Prerequisites
● A running Kubernetes cluster.
●Portainer Business Edition is already installed and configured.
● A Git repository containing a list of Kubernetes resources or a Helm diagram.
step1Navigate to the app and select "Create from manifest".
⑴Log in PortainerAnd select yourKubernetesenvironment.
⑵Navigate toapplicationpart.
⑶ClickCreate from listStart using the storedGitThe process of deploying applications from inventory lists in a repository.
step2Use manifest configurationGitOps
When prompted, you need to configure yourGitWarehouse connection:
(1) Namespace:Decide whether you want to use the namespace specified in the list, or override and manually select the target namespace.
(2) Certification:If youGitThe warehouse requires authentication; please add credentials.
(3) WarehouseURL:Input storageKubernetesConfiguration listGit URL(For example,GitHub、GitLab)。
(4) Repository Reference:Specify what you want to deployGitBranches (usually)main ormaster)。
(5) Configuration list path:Provide the path to the configuration manifest in the repository (e.g.,/manifests/deployment.yamlYou can add multiple configuration manifest paths to your application.
This is basic. deployment.yaml Example:
Once you have configured the connection to your repositoryPortainerIt will be acquired and applied to yourKubernetesThe manifest file in the environment.
step3:set upGitOps Automatic synchronization
During the setup process, you can configure PortainerAutomatic andGitRepository synchronization. This ensures that changes pushed to the repository (such as new image versions or configuration updates) are automatically applied to your repository.KubernetesCluster.
⑴GitOpsUpdate: Select to enableGitOpsCoordination engine.
(2) Mechanism:If you prefer push-based updates, you can choose to enable polling (default) or Webhook。
⑶Get Interval:You can configurePortainerCheck your [service] once in a whileGitRepository updates (e.g., every5 minute).
(4) Always use the list:This option ensures that any local changes that take effect in the cluster will be overridden, even if...GitThere was no change in the warehouse.
(5) SkipTLSverify:If you areGitUsing a self-signed certificate in the repository can disable...TLSwarn.
III. Application Scenarios
①UseGitOps Automatic application updates
Suppose you manage aGitOpsexistPortainerContainerization deployed in ChinaWeb Service. This application is a basic one.Nginx Webserver.
Workflow example:
The team deployment.yaml Lieutenant GeneralDocker Image version fromnginx:1.17 Updated tonginx:1.18。
They then pushed the updated list toGitwarehousemainBranch.
PortainerofGitOps The feature detects the change (based on your configured synchronization interval) and automatically redeploys the updated application.KubernetesSwitch to the newnginx Mirror version.
Key advantages:
●Automation: No manual updates required, ensuring the application always stays updated.GitMatches the latest configuration in [the system/system].
●Consistency: The operating environment consistently reflects...GitThe desired state as defined in [the document/reference].
②UseGitOpsPerform rollback
PortainerInGitOpsIt also simplifies the rollback process, helping teams quickly restore to a previously known good state when problems occur during the update process.
Workflow example:
In deployment nginx:1.18 Afterwards, you discovered that the new version introduced abug。
To roll back, simply... Git Revert changes in the repository to the previous state.nginx:1.17 Version:
Then push the changes to Git storehouse.
PortainerUpdates are detected automatically, and previous working versions are used.(nginx:1.17) Redeploy toKubernetesThis effectively rolled back the change.
Main advantages:
●Easy rollback: Simply roll back changes in Git and let Portainer handle the redeployment.●Version control: Because all changes are recorded in Git In the middle, you have a complete audit log of all deployments.
③Multiple environmentsGitOps deploy
If you manage multiple environments, such as development, testing, and production environments, you can usePortainerofGitOpsTo manage the deployment of all environments in a consistent and controllable manner.
Workflow example:
Each environment (development, testing, production) is linked to yourGitDifferent branches in the warehouse.
●Development: dev Branches
●Preview:staging Branches
●Production:main Branches
Developers will push changes todevOnce the branch passes testing, they will merge the changes into it.stagingThe branch was used for further verification.
Finally, once the changes are validated, the code will be merged into...mainBranches,PortainerIt will be automatically deployed to production.KubernetesCluster.
Key advantages:
Environmental isolation:Create independent environmentsGitBranches prevent untested changes from entering the production environment.
automation:Portaineraccording toGitBranch updates will be automatically deployed to the correct environment.
Portainer ofGitOpsSupport for crossKubernetesEnvironmental management and automated application deployment offer powerful capabilities. By...GitAs a provenance source, you can ensure consistency, reliability, and traceability throughout the deployment process. Whether you need automatic updates, easy rollback, or multi-environment management,PortainerofGitOpsAll for youKubernetesThe workload provides a flexible and scalable solution.
Nebula Data, headquartered in Singapore with branches in Guangzhou, Shanghai, and Hong Kong, is a leading cloud-network integrated and intelligent computing power service provider, focusing on serving Chinese enterprises expanding globally. It offers integrated solutions combining global AIDC (AI Computing Center) + low-latency networks + converged cloud management, empowering enterprises to embrace AI and expand globally.