【题目1】Pod管理
在master节点/root目录下编写yaml文件nginx.yaml,具体要求如下:
(1)Pod名称:nginx-pod;
(2)命名空间:default;
(3)容器名称:mynginx;
(4)镜像:nginx;拉取策略:IfNotPresent;
(5)容器端口:80。
[root@k8s-master kkkkk]# vi nginx.yaml
apiVersion: v1
kind: Pod
metadata:
name: nginx-pod
namespace: default
spec:
containers:
- image: nginx
imagePullPolicy: IfNotPresent
name: mynginx
ports:
- containerPort: 80
【题目2】Namespace管理
在master节点/root目录下编写yaml文件my-namespace.yaml,具体要求如下:
(1)Namespace名称:test
[root@k8s-master kkkkk]# vi namespace001.yaml
apiVersion: v1
kind: Namespace
metadata:
name: test
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
[root@k8s-master kkkkk]# vi nginx-deployment.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: nginx-deployment
namespace: default
spec:
replicas: 2
selector:
matchLabels:
app: myapp
template:
metadata:
labels:
app: myapp
spec:
containers:
- image: nginx
imagePullPolicy: IfNotPresent
name: my-dep-pod
ports:
- containerPort: 80
hostNetwork: true
【题目4】Service管理
在master节点/root目录下编写yaml文件service-clusterip.yaml,具体要求如下:
(1)Service名称:service-clusterip;
(2)命名空间:default;
(3)集群内部访问端口:80;targetPort: 81;
(4)Service类型:ClusterIP。
[root@k8s-master kkkkk]# vi service-clusterip.yaml
apiVersion: v1
kind: Service
metadata:
name: service-clusterip
namespace: default
spec:
selector:
app: myapp
ports:
- name: nginx-svc
protocol: TCP
port: 80
targetPort: 81
type: ClusterIP
【题目5】RBAC管理
在master节点/root目录下编写yaml文件role.yaml,具体要求如下:
(1)Role名称:pod-reader;
(2)命名空间:default;
(3)对default命名空间内的Pod拥有get、watch、list的权限。
[root@k8s-master kkkkk]# vi role.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: pod-reader
namespace: default
rules:
- apiGroups: [""]
resources: ["pods"]
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。
[root@k8s-master kkkkk]# vi pv.py
apiVersion: v1
kind: PersistentVolume
metadata:
name: mypv001
namespace: default
spec:
volumeMode: Filesystem
capacity:
storage: 5Gi
storageClassName: mypv
persistentVolumeReclaimPolicy: Delete
local:
path: /home/pv001
accessModes:
- ReadWriteOnce
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- k8s-node1
【题目4】HPA管理
在master节点/root目录下编写yaml文件hpa.yaml,具体要求如下:
(1)HPA名称:frontend-scaler;
(2)命名空间:default;
(3)副本数伸缩范围:3—10;
(4)期望每个Pod的CPU使用率为50%。
[root@k8s-master kkkkk]# vi hpa.yaml
apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
name: frontend-scaler
namespace: default
spec:
maxReplicas: 10
minReplicas: 2
targetCPUUtilizationPercentage: 50
scaleTargetRef:
apiVersion: extensions/v1beta1
kind: Deployment
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。