创建1个名为 qc01ex01-eid 的 pod,在 pod 里面分别为以下每个 images 单独运行一个container: nginx+redis+busybox(提示,1个pod可以包含多个container)
C:\Users\fan.hai> kubectl run qc01xe01-fan.hai --image=nginx --dry-run=client -o yaml >qc01ex01.yaml
② 创建1个的deployment:
名字为qc01ex02-eid,使用image为 nginx,版本为1.11.9-alpine. 此 deployment 需要包含 3 replicas。 然后使用rolling update把此 deployment的nginx版本升级为1.12.0-alpine ,成功以后再把此次升级rollback回1.11.9-alpine。
1. 创建deployment
kubectl create deployment qc01xe02-fan.hai --image=nginx:1.11.9-alpine --replicas=3 --dry-run=client -o yaml > qc01xe02.yaml(为了得到deployment模板) 检查本地yaml没问题后,执行kubectl apply -f qc01xe02.yaml
2. 升级deployment
a. 执行命令 kubectl edit deployment qc01xe02-fan.hai 弹出文本窗口
b. 更改版本号后,系统自动update
c. 执行命令: kubectl rollout status deployment qc01xe02-fan.hai /kubectl rollout history deployment qc01xe02-fan.hai
3. 回滚
a. kubectl rollout undo deployment qc01xe02-fan.hai
③ 创建1个名为top-scecret的Kubernetes Secret,内容为 username: bob ,使用redis image创建1个名为qc01ex03-eid的pod并把创建好的secret挂载到pod的/secrets 目录下。
1. 创建secret命令:
kubectl create secret generic top-secret --from-literal=username=bob
2. 新建pod,以yaml文件格式输出
kubectl run qc01ex03 --image=redis --dry-run=client -o yaml >qc01ex03.yaml
更改yaml文件 注意对齐格式
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
run: qc01ex03
name: qc01ex03
spec:
containers:
- image: redis
name: qc01ex03
volumeMounts:
- name: top-secret
mountPath: “/secrets”
readOnly: true
volumes:
- name: top-secret
secret:
secretName: top-secret
输入命令行 kubectl apply -f qc01ex03.yaml --dry-run=server 不用dry run