Files
docker_practice/11_orchestration/kubernetes/advanced.md

62 lines
2.2 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Kubernetes 高级特性
掌握了 Kubernetes 的核心概念Pod, Service, Deployment我们需要了解更多高级特性以构建生产级应用
## Helm - 包管理工具
[Helm](https://helm.sh/) 被称为 Kubernetes 的包管理器(类似于 Linux 的 apt/yum。它将一组 Kubernetes 资源定义文件打包为一个 **Chart**。
* **安装应用**`helm install my-release bitnami/mysql`
* **版本管理**轻松回滚应用的发布版本
* **模板化**支持复杂的应用部署逻辑配置
## Ingress - 服务的入口
Service 虽然提供了负载均衡但通常是 4 TCP/UDP**Ingress** 提供了 7 HTTP/HTTPS路由能力充当集群的网关
* **域名路由**基于 Host 将请求转发不同服务 (api.example.com -> api-svc, web.example.com -> web-svc)
* **路径路由**基于 Path 将请求转发 (/api -> api-svc, / -> web-svc)
* **SSL/TLS**集中管理证书
常见的 Ingress Controller有 Nginx Ingress Controller, Traefik, Istio Gateway
## Persistent Volume (PV) StorageClass
容器内的文件是临时的对于有状态应用如数据库需要持久化存储
* **PVC (Persistent Volume Claim)**用户申请存储的声明
* **PV (Persistent Volume)**实际的存储资源NFS, AWS EBS, Ceph
* **StorageClass**定义存储类支持动态创建 PV
## Horizontal Pod Autoscaling (HPA)
HPA 根据 CPU 利用率或其他指标如内存自定义指标自动扩缩 Deployment ReplicaSet 中的 Pod 数量
```yaml
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: php-apache
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: php-apache
minReplicas: 1
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 50
```
## ConfigMap Secret
* **ConfigMap**存储非机密的配置数据配置文件环境变量
* **Secret**存储机密数据密码Token证书 Etcd 中加密存储
通过将配置与镜像分离保证了容器的可移植性