【题目1】Pod管理

在master节点/root目录下编写yaml文件nginx.yaml,具体要求如下:
(1)Pod名称:nginx-pod;
(2)命名空间:default;
(3)容器名称:mynginx;
(4)镜像:nginx;拉取策略:IfNotPresent;
(5)容器端口:80。

  1. [root@k8s-master kkkkk]# vi nginx.yaml
  2. apiVersion: v1
  3. kind: Pod
  4. metadata:
  5. name: nginx-pod
  6. namespace: default
  7. spec:
  8. containers:
  9. - image: nginx
  10. imagePullPolicy: IfNotPresent
  11. name: mynginx
  12. ports:
  13. - containerPort: 80

【题目2】Namespace管理

在master节点/root目录下编写yaml文件my-namespace.yaml,具体要求如下:
(1)Namespace名称:test

  1. [root@k8s-master kkkkk]# vi namespace001.yaml
  2. apiVersion: v1
  3. kind: Namespace
  4. metadata:
  5. name: test
  6. spec:

【题目3】Deployment管理

在master节点/root目录下编写yaml文件nginx-deployment.yaml,具体要求如下:
(1)Deployment名称:nginx-deployment;
(2)命名空间:default;
(3)Pod名称:nginx-deployment,副本数:2;
(4)网络:hostNetwork;
(5)镜像:nginx;
(6)容器端口:80

  1. [root@k8s-master kkkkk]# vi nginx-deployment.yaml
  2. apiVersion: extensions/v1beta1
  3. kind: Deployment
  4. metadata:
  5. name: nginx-deployment
  6. namespace: default
  7. spec:
  8. replicas: 2
  9. selector:
  10. matchLabels:
  11. app: myapp
  12. template:
  13. metadata:
  14. labels:
  15. app: myapp
  16. spec:
  17. containers:
  18. - image: nginx
  19. imagePullPolicy: IfNotPresent
  20. name: my-dep-pod
  21. ports:
  22. - containerPort: 80
  23. hostNetwork: true

【题目4】Service管理

在master节点/root目录下编写yaml文件service-clusterip.yaml,具体要求如下:
(1)Service名称:service-clusterip;
(2)命名空间:default;
(3)集群内部访问端口:80;targetPort: 81;
(4)Service类型:ClusterIP。

  1. [root@k8s-master kkkkk]# vi service-clusterip.yaml
  2. apiVersion: v1
  3. kind: Service
  4. metadata:
  5. name: service-clusterip
  6. namespace: default
  7. spec:
  8. selector:
  9. app: myapp
  10. ports:
  11. - name: nginx-svc
  12. protocol: TCP
  13. port: 80
  14. targetPort: 81
  15. type: ClusterIP

【题目5】RBAC管理

在master节点/root目录下编写yaml文件role.yaml,具体要求如下:
(1)Role名称:pod-reader;
(2)命名空间:default;
(3)对default命名空间内的Pod拥有get、watch、list的权限。

  1. [root@k8s-master kkkkk]# vi role.yaml
  2. apiVersion: rbac.authorization.k8s.io/v1
  3. kind: Role
  4. metadata:
  5. name: pod-reader
  6. namespace: default
  7. rules:
  8. - apiGroups: [""]
  9. resources: ["pods"]
  10. verbs: ["get","watch","list"]

【题目6】PV管理

在master节点/root目录下编写yaml文件pv.yaml,具体要求如下:
(1)PV名称: ;
(2)命名空间:default;
(3)回收策略:Delete;
(4)访问模式:RWO;
(5)挂载路径:node节点/data/k8s/localpv;
(6)卷容量:5G。

  1. [root@k8s-master kkkkk]# vi pv.py
  2. apiVersion: v1
  3. kind: PersistentVolume
  4. metadata:
  5. name: mypv001
  6. namespace: default
  7. spec:
  8. volumeMode: Filesystem
  9. capacity:
  10. storage: 5Gi
  11. storageClassName: mypv
  12. persistentVolumeReclaimPolicy: Delete
  13. local:
  14. path: /home/pv001
  15. accessModes:
  16. - ReadWriteOnce
  17. nodeAffinity:
  18. required:
  19. nodeSelectorTerms:
  20. - matchExpressions:
  21. - key: kubernetes.io/hostname
  22. operator: In
  23. values:
  24. - k8s-node1

【题目4】HPA管理

在master节点/root目录下编写yaml文件hpa.yaml,具体要求如下:
(1)HPA名称:frontend-scaler;
(2)命名空间:default;
(3)副本数伸缩范围:3—10;
(4)期望每个Pod的CPU使用率为50%。

  1. [root@k8s-master kkkkk]# vi hpa.yaml
  2. apiVersion: autoscaling/v1
  3. kind: HorizontalPodAutoscaler
  4. metadata:
  5. name: frontend-scaler
  6. namespace: default
  7. spec:
  8. maxReplicas: 10
  9. minReplicas: 2
  10. targetCPUUtilizationPercentage: 50
  11. scaleTargetRef:
  12. apiVersion: extensions/v1beta1
  13. kind: Deployment
  14. name: nginx-deployment

【题目5】健康检查

在master节点/root目录下编写yaml文件liveness_httpget.yaml,具体要求如下:
(1)Pod名称:liveness-http;
(2)命名空间:default;
(3)镜像:nginx;端口:80;
(4)容器启动时运行命令“echo Healty > /usr/share/nginx/html/healthz”;
(5)httpGet请求的资源路径为/healthz,地址默认为Pod IP,端口使用容器中定义的端口名称HTTP;
(6)启动后延时30秒开始运行检测;
(7)每隔3秒执行一次liveness probe。