This is the multi-page printable view of this section. Click here to print.
Operations
- 1: Ansible
- 2: Kubernetes
- 3: OpenTelemetry
- 4: GitOps
1 - Ansible
Ansible
Ansible là một công cụ tự động hóa IT mã nguồn mở, giúp quản lý cấu hình, triển khai ứng dụng và điều phối nhiệm vụ.
Tính năng chính
- Agentless: Không yêu cầu cài đặt agent trên các máy đích
- Declarative: Sử dụng YAML để mô tả trạng thái mong muốn
- Idempotent: Có thể chạy nhiều lần mà không gây ra tác dụng phụ
- Extensible: Dễ dàng mở rộng với modules và plugins
Playbooks
Playbooks là tệp YAML định nghĩa các nhiệm vụ tự động hóa trong Ansible.
Inventory
Inventory là danh sách các máy chủ mà Ansible quản lý, có thể được nhóm và phân cấp.
2 - Kubernetes
Overview
Kubernetes is an open-source container orchestration platform for automating deployment, scaling, and management of containerized applications.
Basic Concepts
| Concept | Description |
|---|---|
| Pod | Smallest deployable unit that can contain one or more containers |
| Node | Worker machine in the Kubernetes cluster |
| Cluster | Set of nodes that run containerized applications |
| Deployment | Manages the desired state for Pods and ReplicaSets |
| Service | Defines a logical set of Pods and a policy to access them |
| Namespace | Virtual cluster within a physical cluster |
Common Commands
| Command | Description |
|---|---|
kubectl get pods | List all pods in the current namespace |
kubectl apply -f file.yaml | Create or update resources from a file |
kubectl describe pod <pod-name> | Show detailed information about a pod |
kubectl logs <pod-name> | Print the logs from a container in a pod |
kubectl exec -it <pod-name> -- /bin/bash | Execute a command in a container |
2.1 - Port Forward Kubernetes
Syntax
NS=<namespace>; kubectl -n $NS port-forward $(kubectl -n $NS get pods -l app=<[production,staging,production-postgres,staging-postgres]> | awk 'NR==2{print$1}') <local_port>:<container_port>
- Ví dụ tạo kết nối đến DB staging của Collector
điền NS=collector-8148254 APP=staging-postgres
lệnh: NS=collector-8148254 APP=staging-postgres; kubectl -n $NS port-forward $(kubectl -n $NS get pods -l app=$APP | awk 'NR==2{print$1}') 5432:5432
- Tạo kết nối đế n ứng dụng collector staging để truy cập bằng localhost:8080
lệnh: NS=collector-8148254 APP=staging; kubectl -n $NS port-forward $(kubectl -n $NS get pods -l app=$APP | awk 'NR==2{print$1}') 8080:5000
3 - OpenTelemetry
OpenTelemetry
OpenTelemetry (OTel) là một framework mã nguồn mở để thu thập dữ liệu telemetry từ các ứng dụng và dịch vụ. OTel cung cấp các API, thư viện, agent và công cụ thu thập để tạo, quản lý và xuất dữ liệu telemetry (logs, metrics, và traces) đến các backend phân tích.
Thành phần chính
- Traces: Theo dõi luồng yêu cầu qua các dịch vụ
- Metrics: Thu thập dữ liệu số liệu về hiệu suất hệ thống
- Logs: Ghi lại các sự kiện xảy ra trong hệ thống
Lợi ích
- Chuẩn hóa việc thu thập dữ liệu telemetry
- Giảm thiểu vendor lock-in
- Tích hợp dễ dàng với nhiều backend phân tích
- Hỗ trợ đa ngôn ngữ lập trình
4 - GitOps
Example workflow
sequenceDiagram
participant Dev as Developer
participant GL as GitLab
participant TFC as Terraform Cloud
participant CF as Cloudflare
Dev->>GL: Update members.yaml
GL->>GL: Merge to master
GL->>TFC: Trigger pipeline
TFC->>CF: Update Zero Trust access permissions
Note over CF: Application access policies updatedIn this example, a developer updates the members.yaml file,
which contains the list of members who have access to the site.
Another developer review then merges the changes to the master branch,
triggering a pipeline in Terraform Cloud.
The pipeline updates the Zero Trust access permissions in Cloudflare,
updating the application access policies.