In today's era of cloud computing and DevOps, managing and maintaining multiple cluster environments has become a challenge. Each cluster has its unique characteristics and requirements, such as development, testing, production, etc. Effectively managing these clusters requires careful planning and the right tools.
The objective of this document is to demonstrate how to effectively manage multiple K8S clusters, covering different environments such as development, testing, and production. The key is to leverage automation tools and best practices to achieve efficient and reliable operational processes.
Detailed description of the objectives:
Project | Service Provider | Purpose/Environment | Notes |
---|---|---|---|
Cloud Account | Google Cloud Platform (GCP) | General | Access and manage cloud resources |
Domain | xx Cloud | Development Environment | svc-sit.ink |
Domain | xx Cloud | Testing Environment | svc-uat.ink |
Domain | xx Cloud | Production Environment | svc.ink |
Cloud DNS Service | Alibaba Cloud | Domain Resolution | Using xx Cloud's SaaS services |
CI/CD | GitHub Action | Automated Build, Test, Deployment | Facilitating CI/CD processes |
First, declare resource configurations in the configuration repository, followed by using the GitHub CI pipeline to automate the resource application process. Below are the detailed expansions of these two steps:
In the iac_modules repository, the file iac_modules/terraform/gcp/vhost/config.yaml defines the resources needed in GCP. This YAML file details different instances for various purposes (such as devops, monitor, sit, uat, and prod), each with specific specifications like CPU type, memory size, storage size, and region.
region: "asia-northeast1"
project_id: "cloudsvcsandbox"
bucket_name: "iac_gcp_terraform_state"
instances:
- name: "devops"
type: "e2-standard-4"
zone: "asia-northeast1-a"
image: "ubuntu-2004-lts"
disk_size_gb: 100
network: "custom"
subnetwork: internet-subnet
- name: "monitor"
type: "e2-standard-4"
zone: "asia-northeast1-a"
image: "ubuntu-2004-lts"
disk_size_gb: 100
network: "custom"
subnetwork: internet-subnet
- name: "sit"
image: "ubuntu-2004-lts"
disk_size_gb: 100
type: "e2-standard-2"
zone: "asia-northeast1-a"
network: "custom"
subnetwork: internet-subnet
- name: "uat"
type: "e2-standard-4"
zone: "asia-northeast1-a"
image: "ubuntu-2004-lts"
disk_size_gb: 100
network: "custom"
subnetwork: internet-subnet
- name: "prod"
type: "e2-standard-4"
zone: "asia-northeast1-a"
image: "ubuntu-2004-lts"
disk_size_gb: 100
network: "custom"
subnetwork: internet-subnet
or more IAC configurations, see the https://github.com/svc-design/iac_modules.git repository, which includes key elements such as region and project ID, storage bucket for Terraform state management, subnet divisions, routing, firewall rules, etc.
In the .github/workflows/iac-pipeline-create.yml file, a GitHub CI pipeline is defined to automate the resource request declared in the config.yaml. The pipeline uses GitHub Actions to execute Terraform scripts automatically, creating and configuring resources defined in GCP.
After the pipeline runs successfully, the resources are ready in the GCP console, and the basic configuration for each environment is completed.
In the GitOps configuration repository, a directory structure is created to organize monitoring-related configuration files. For example, kube-prometheus-stack and observability-agent folders contain related configurations and Kustomize files.
apps/
├── monitor
│ ├── kube-prometheus-stack
│ │ ├── kube-state-metrics-config.yaml
│ │ ├── kustomization.yaml
│ │ ├── kustomizeconfig.yaml
│ │ ├── release.yaml
│ │ └── repository.yaml
│ └── observability-agent
│ ├── kustomization.yaml
│ └── release.yaml
Using kustomization.yaml files defined in the GitOps repository, you can specify which resources should be applied to specific Kubernetes clusters. For example, in clusters/sit/kustomization.yaml, resources and configurations to be applied to the SIT environment are specified.
Kustomization File Example
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- namespace.yaml
- ../../apps/monitor/observability-agent/
- ../../apps/monitor/kube-prometheus-stack/
These configurations are applied to the SIT environment's cluster within minutes after code submission. Configuration changes can be viewed via the Grafana panel showing FluxCD sync status.
Managing and changing configurations, especially monitoring and alert systems in a multi-cluster environment, using the GitOps repository provides significant efficiency and convenience. This approach allows teams to use familiar Git workflows to manage complex configurations while ensuring consistency and traceability across environments.
By adding monitoring configuration files to the GitOps repository as shown:
clusters/monitor/kustomization.yaml
clusters/monitor/recording-rules-patch.yaml
clusters/monitor/alert-rules-patch.yaml
Using GitOps achieves several key operational goals:
Once these configurations are applied to the cluster, Grafana displays real-time data and alerts based on these rules.
Using GitOps and Kustomize tools to manage and publish multiple applications. This method provides a highly automated and declarative way to handle the deployment and management of Kubernetes resources.
apps/
├── c-demo
│ ├── kustomization.yaml
│ ├── namespace.yaml
│ └── release.yaml
├── go-demo
│ ├── kustomization.yaml
│ ├── namespace.yaml
│ └── release.yaml
├── js-demo
│ ├── kustomization.yaml
│ └── namespace.yaml
├── python-demo
│ ├── kustomization.yaml
│ ├── namespace.yaml
│ └── release.yaml
└── rust-demo
├── kustomization.yaml
├── namespace.yaml
└── release.yaml
In the apps/ directory, each subdirectory (like c-demo, go-demo, js-demo, python-demo, rust-demo) represents an independent application. Each application directory contains its own kustomization.yaml, namespace.yaml, and release.yaml.
In clusters/sit/kustomization.yaml, the resources to be deployed in the SIT environment cluster are defined:
Kustomization File Example
clusters/sit/kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- namespace.yaml
- ../../apps/monitor/observability-agent/
- ../../apps/monitor/kube-prometheus-stack/
- ../../apps/c-demo/
- ../../apps/js-demo/
- ../../apps/python-demo/
- ../../apps/go-demo/
- ../../apps/rust-demo/
Once these configurations are applied to the Kubernetes clusters by the GitOps tool, Grafana displays the deployment status and operation of these applications.
Subsequently, appropriate Dashboards in Grafana can be set up to monitor more application status information, such as application performance metrics, health checks and availability, alerts and events.
The pipeline excels in automating the initialization and setup of infrastructure. Its main advantages include:
GitOps is more efficient in application deployment and configuration changes, especially in CD and configuration management:
The importance and complementarity of GitOps and Pipeline-based DevOps in modern software engineering are evident. Together, they not only improve the efficiency and quality of software development and operations but also provide organizations with the ability to adapt to rapid changes. Additionally, with the increase in the number of applications, adopting templated and standardized strategies helps to maintain manageability of workloads and prevent linear workload growth with scale. The above operational practices provide strong support for rapid development and operations of modern cloud-native applications.
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。