Skip to content

Latest commit

 

History

History
93 lines (78 loc) · 1.58 KB

File metadata and controls

93 lines (78 loc) · 1.58 KB

8.2 Kubernetes核心实战

📍 导航返回目录 | 上一节:Docker | 下一节:CI/CD


核心对象

Deployment

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app
spec:
  replicas: 3
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
    spec:
      containers:
      - name: app
        image: my-app:v1.0.0
        ports:
        - containerPort: 8080
        resources:
          limits:
            cpu: "1"
            memory: "512Mi"
          requests:
            cpu: "500m"
            memory: "256Mi"

Service

apiVersion: v1
kind: Service
metadata:
  name: my-app-service
spec:
  selector:
    app: my-app
  ports:
  - protocol: TCP
    port: 80
    targetPort: 8080
  type: LoadBalancer

HPA(自动扩缩容)

apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: my-app-hpa
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: my-app
  minReplicas: 2
  maxReplicas: 10
  metrics:
  - type: Resource
    resource:
      name: cpu
      target:
        type: Utilization
        averageUtilization: 70

本章小结

关键要点

  • ✅ Deployment管理应用
  • ✅ Service提供访问
  • ✅ HPA自动扩缩容
  • ✅ ConfigMap/Secret配置管理

⏮️ 上一节:Docker | ⏭️ 下一节:CI/CD