# Argo-CD **Repository Path**: heathcliffs/argo-cd ## Basic Information - **Project Name**: Argo-CD - **Description**: No description available - **Primary Language**: Unknown - **License**: Zlib - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2025-09-10 - **Last Updated**: 2025-09-12 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Kubernetes 演示项目 本仓库包含使用 ArgoCD 和 Helm 进行 Kubernetes 部署的演示配置。 ## 项目结构 ``` ├── argo-demo/ # ArgoCD 部署配置 │ ├── nginx-deployment.yaml │ ├── nginx-service.yaml │ ├── zookeeper-deployment.yaml │ ├── kafka-deployment.yaml │ ├── kafka-ui-deployment.yaml │ ├── elasticsearch-deployment.yaml │ ├── kibana-deployment.yaml │ └── logstash-deployment.yaml ├── helm-nginx/ # nginx 的 Helm chart └── README.md # 本文件 ``` ## 组件说明 ### ArgoCD 演示 (`argo-demo/`) 包含使用 ArgoCD 部署多个服务的 Kubernetes 清单文件: **Nginx 服务:** - **nginx-deployment.yaml**: nginx 的 Kubernetes Deployment 配置 - **nginx-service.yaml**: 暴露 nginx 服务的 Kubernetes Service 配置 **Kafka 消息队列:** - **zookeeper-deployment.yaml**: Zookeeper 的 Deployment 和 Service 配置(Kafka 依赖) - **kafka-deployment.yaml**: Kafka 的 Deployment 和 Service 配置 - **kafka-ui-deployment.yaml**: Kafka UI 管理界面的 Deployment 和 Service 配置 **Elasticsearch 日志分析栈(ELK):** - **elasticsearch-deployment.yaml**: Elasticsearch 搜索引擎的 Deployment 和 Service 配置 - **kibana-deployment.yaml**: Kibana 数据可视化界面的 Deployment 和 Service 配置 - **logstash-deployment.yaml**: Logstash 日志处理管道的 Deployment 和 Service 配置 **监控和指标收集:** - **metricbeat-deployment.yaml**: Metricbeat 指标收集器,收集 Kafka、系统和容器指标 ### Helm Nginx (`helm-nginx/`) nginx 部署的 Helm chart 目录(正在配置中)。 ## 前置要求 - Kubernetes 集群(本地或云端) - 已配置 kubectl 访问集群 - 集群中已安装 ArgoCD(用于 ArgoCD 演示) - 已安装 Helm 3.x(用于 Helm charts) ## 开始使用 ### ArgoCD 部署步骤 #### 1. 安装 ArgoCD 创建命名空间并安装 ArgoCD: ```bash # 创建 argocd 命名空间 kubectl create namespace argocd # 安装 ArgoCD kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml ``` #### 2. 等待 ArgoCD 组件启动 ```bash # 检查 ArgoCD 组件状态 kubectl get pods -n argocd # 等待所有 pod 运行 kubectl wait --for=condition=Ready pods --all -n argocd --timeout=300s ``` #### 3. 访问 ArgoCD UI 获取 ArgoCD 服务器的访问方式: **方法一:使用 Port Forward** ```bash # 端口转发到本地 kubectl port-forward svc/argocd-server -n argocd 8080:443 # 然后在浏览器访问 https://localhost:8080 ``` **方法二:修改服务类型为 NodePort** ```bash # 修改服务类型 kubectl patch svc argocd-server -n argocd -p '{"spec":{"type":"NodePort"}}' # 获取访问端口 kubectl get svc argocd-server -n argocd ``` #### 4. 获取 ArgoCD 初始密码 ```bash # 获取初始 admin 密码 kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d && echo ``` 默认用户名是 `admin` #### 5. 安装 ArgoCD CLI(可选) **macOS:** ```bash brew install argocd ``` **Linux:** ```bash 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 ``` #### 6. 使用 CLI 登录(可选) ```bash # 登录 ArgoCD argocd login localhost:8080 # 修改密码(推荐) argocd account update-password ``` #### 7. 部署应用 ```bash # 直接应用 nginx 配置 kubectl apply -f argo-demo/ # 或者创建 ArgoCD Application argocd app create nginx-demo \ --repo https://gitee.com/heathcliffs/argo-cd.git \ --path argo-demo \ --dest-server https://kubernetes.default.svc \ --dest-namespace default ``` ### 使用 Helm 1. 进入 helm-nginx 目录: ```bash cd helm-nginx ``` 2. 安装 chart(配置完成后): ```bash helm install nginx-demo . ``` ## 访问应用 部署完成后,可以根据服务配置和集群设置访问各个服务。 ### 查看服务状态 ```bash # 查看所有服务状态 kubectl get svc # 查看所有 pod 状态 kubectl get pods # 查看特定服务详情 kubectl get svc nginx-service -o wide kubectl get svc kafka-service -o wide kubectl get svc kafka-ui-service -o wide kubectl get svc elasticsearch-service -o wide kubectl get svc kibana-service -o wide kubectl get svc logstash-service -o wide # 查看 Metricbeat 状态 kubectl get pods -l app=metricbeat ``` ### 访问 Nginx ```bash # 如果是 NodePort 类型,获取访问端口 kubectl get svc nginx-service ``` ### 访问 Kafka UI Kafka UI 提供了一个 Web 界面来管理和监控 Kafka 集群: ```bash # 获取 Kafka UI 的访问端口 kubectl get svc kafka-ui-service # 使用端口转发访问(推荐用于开发环境) kubectl port-forward svc/kafka-ui-service 8080:8080 # 然后在浏览器访问 http://localhost:8080 ``` ### 测试 Kafka 你可以使用 Kafka 客户端工具测试消息队列功能: ```bash # 进入 Kafka pod(注意现在有两个容器,需要指定容器名) kubectl exec -it deployment/kafka -c kafka -- bash # 创建一个测试主题 kafka-topics --create --topic test-topic --bootstrap-server localhost:9092 --partitions 1 --replication-factor 1 # 列出所有主题 kafka-topics --list --bootstrap-server localhost:9092 # 发送消息(生产者) kafka-console-producer --topic test-topic --bootstrap-server localhost:9092 # 接收消息(消费者,在另一个终端中运行) kafka-console-consumer --topic test-topic --from-beginning --bootstrap-server localhost:9092 ``` ### 查看 Kafka 日志收集 现在 Kafka 部署包含了 Filebeat sidecar 容器,会自动将 Kafka 日志发送到 Elasticsearch: ```bash # 查看 Kafka 容器日志 kubectl logs deployment/kafka -c kafka # 查看 Filebeat 容器日志 kubectl logs deployment/kafka -c filebeat # 检查 Kafka 日志文件 kubectl exec -it deployment/kafka -c kafka -- ls -la /kafka-logs/ # 查看 Elasticsearch 中的 Kafka 日志索引 curl -X GET "localhost:9200/kafka-logs-*/_search" -H 'Content-Type: application/json' -d' { "query": { "match_all": {} }, "size": 10, "sort": [ { "@timestamp": { "order": "desc" } } ] }' ``` ### 在 Kibana 中查看 Kafka 日志和指标 1. 访问 Kibana UI: http://localhost:5601 2. 进入 "Stack Management" -> "Index Patterns" 3. 创建索引模式: - `kafka-logs-*` (Kafka 日志) - `metricbeat-kafka-*` (Kafka 指标) 4. 选择时间字段: `@timestamp` 5. 进入 "Discover" 查看数据 ### 查看 Kafka 指标 ```bash # 查看 Metricbeat 收集的 Kafka 指标 curl -X GET "localhost:9200/metricbeat-kafka-*/_search" -H 'Content-Type: application/json' -d' { "query": { "bool": { "must": [ {"term": {"metricset.module": "kafka"}}, {"range": {"@timestamp": {"gte": "now-1h"}}} ] } }, "size": 10, "sort": [{"@timestamp": {"order": "desc"}}] }' # 查看 Kafka broker 指标 curl -X GET "localhost:9200/metricbeat-kafka-*/_search" -H 'Content-Type: application/json' -d' { "query": { "bool": { "must": [ {"term": {"metricset.name": "broker"}}, {"range": {"@timestamp": {"gte": "now-10m"}}} ] } }, "size": 5 }' ``` ### Metricbeat 收集的指标类型 - **Kafka Broker 指标**: 消息吞吐量、字节传输、分区信息 - **Kafka Topic 指标**: 每个主题的消息数量、大小 - **Kafka Consumer 指标**: 消费者组状态、延迟 - **Kafka Producer 指标**: 生产者性能指标 - **JMX 指标**: JVM 内存、GC、线程等 - **系统指标**: CPU、内存、网络、磁盘使用情况 - **容器指标**: Docker 容器资源使用情况 ### 访问 Elasticsearch 和 Kibana Elasticsearch 提供了强大的搜索和分析功能,Kibana 提供了数据可视化界面: ```bash # 获取 Kibana 的访问端口 kubectl get svc kibana-service # 使用端口转发访问 Kibana(推荐用于开发环境) kubectl port-forward svc/kibana-service 5601:5601 # 然后在浏览器访问 http://localhost:5601 ``` ### 测试 Elasticsearch 你可以使用 REST API 测试 Elasticsearch 功能: ```bash # 使用端口转发访问 Elasticsearch kubectl port-forward svc/elasticsearch-service 9200:9200 # 检查集群健康状态 curl http://localhost:9200/_cluster/health # 创建一个测试索引 curl -X PUT "localhost:9200/test-index" -H 'Content-Type: application/json' -d' { "settings": { "number_of_shards": 1, "number_of_replicas": 0 } }' # 添加一个文档 curl -X POST "localhost:9200/test-index/_doc/1" -H 'Content-Type: application/json' -d' { "user": "test_user", "message": "Hello Elasticsearch!", "timestamp": "2024-01-01T12:00:00" }' # 搜索文档 curl -X GET "localhost:9200/test-index/_search" -H 'Content-Type: application/json' -d' { "query": { "match": { "message": "Hello" } } }' ``` 以下是DevTools的版本 ```bash PUT test-index { "settings": { "number_of_shards": 1, "number_of_replicas": 0 } } POST /test-index/_doc/1 { "user": "test_user", "message": "Hello Elasticsearch!", "timestamp": "2024-01-01T12:00:00" } GET /test-index/_search { "query": { "match": { "message": "Hello" } } } ``` ### 使用 Logstash 处理日志 Logstash 可以接收、处理和转发日志数据: ```bash # 向 Logstash HTTP 输入发送测试数据 kubectl port-forward svc/logstash-service 8080:8080 # 发送测试日志 curl -X POST "localhost:8080" -H 'Content-Type: application/json' -d' { "message": "Test log message", "level": "INFO", "timestamp": "2024-01-01T12:00:00" }' ``` ## 故障排除 ### 常见问题 1. **ArgoCD pods 启动失败** ```bash # 检查资源使用情况 kubectl describe pods -n argocd # 检查节点资源 kubectl top nodes ``` 2. **无法访问 ArgoCD UI** ```bash # 检查服务状态 kubectl get svc -n argocd # 检查防火墙设置 ``` ## 贡献 欢迎提交问题和改进建议! ## 许可证 本项目根据 LICENSE 文件中指定的条款进行许可。