资源清单是 yml 格式,api-server 会自动转成 json 格式
每个 API 对象都有 3 大类属性:元数据 metadata、规范 spec 和状态 status
spec 是期望状态,status 是实际状态,如果实际状态和期望状态有出入,控制器(通常是 deployment 控制器)的控制循环就会监控到差异,然后将需要做出的更改提交到 apiserver,调度器 scheduler 监控到 apiserver 中有未执行的操作,就会去找适合执行操作的 node,然后提交到 apiserver,kubelet 监控到 apiserver 中有关于自己节点的操作,就会执行操作,将执行结果返回给 apiserver,apiserver 再更新实际状态
deployment
HorizontalPodAutoscaler
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| kind: HorizontalPodAutoscaler apiVersion: autoscaling/v2beta1 metadata: namespace: linux42 name: tomcat-app1-podautoscaler labels: app: tomcat-app1 version: v2beta1 spec: scaleTargetRef: kind: Deployment apiVersion: apps/v1 name: tomcat-app1-deployment minReplicas: 2 maxReplicas: 5 metrics: - type: Resource resource: name: cpu targetAverageUtilization: 80 - type: Resource resource: name: memory targetAverageValue: 1024Mi
|
namespace
1 2 3 4
| apiVersion: v1 kind: Namespace metadata: name: test
|
Nginx 业务 yaml 文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
| kind: Deployment apiVersion: extensions/v1beta1 metadata: name: nginx-deployment namespace: test labels: app: nginx-deployment-label spec: replicas: 1 selector: matchLabels: app: nginx-selector template: metadata: labels: app: nginx-selector spec: containers: - name: nginx-container image: harbor.magedu.net/test/nginx-web1:v1 imagePullPolicy: Always ports: - name: http containerPort: 80 protocol: TCP - name: https containerPort: 443 protocol: TCP env: - name: "password" value: "123456" - name: "age" value: "18" resources: limits: cpu: 2 memory: 2Gi requests: cpu: 1 memory: 512Mi --- kind: Service apiVersion: v1 metadata: name: nginx-spec namespace: test labels: app: nginx spec: type: NodePort ports: - name: http port: 80 protocol: TCP targetPort: 80 nodePort: 30001 - name: https port: 443 protocol: TCP targetPort: 443 nodePort: 30043 selector: app: nginx-selector
|