标签:默认 滚动 分布式存储 创建 code eve 特定 lan 容器
四、pod控制器控制器主要分为:
kubectl run nginx1 --image=nginx:1.15-alpine --port=80 --replicas=1
kubectl get deployment
kubectl get pod -o wide
如果本地没有镜像,会自动去下载. nginx:1.15-alpine 比较小巧,下载快.也
可以指定自己的内网镜像仓库来提升下载速度--port=80相当于docker里的暴露端口
--replicas=1指定副本数,默认也为1
apiVersion: apps/v1
kind: Deployment
metadata:
?name: nginx2 # deployment名
spec:
2, 应用YAML文件创建deployment
3, 查看验证
删除deployment
?replicas: 1 # 副本集,deployment里使用了
replicaset
?selector:
??matchLabels:
???app: nginx # 匹配的pod标签,表示deployment和
rs控制器控制带有此标签的pod
?template: # 代表pod的配置模板
??metadata:
???labels:
????app: nginx # pod的标签
??spec:
???containers: # 以下为pod里的容器定义
???- name: nginx
????image: nginx:1.15-alpine
????imagePullPolicy: IfNotPresent
????ports:
????- containerPort: 80
kubectl apply -f nginx2-deployment.yml
kubectl get deployment
kubectl get pods
vim nginx-daemonset.yml
apiVersion: apps/v1
kind: DaemonSet
metadata:
?name: nginx-daemonset
spec:
?selector:
??matchLabels:
???name: nginx-test
?template:
??metadata:
???labels:
????name: nginx-test
??spec:
???tolerations: # tolerations代表容忍
???- key: node-role.kubernetes.io/master ?# 能容忍的污点key
???? effect: NoSchedule ?# kubectl explain pod.spec.tolerations查看(能容忍的污点effect)
???containers:
???- name: nginx
????image: nginx:1.15-alpine
????imagePullPolicy: IfNotPresent
????resources: ??# resources资源限制是为了防止master节点的资源被占太多(根据实际情况配置)
?????limits:
??????memory: 100Mi
?????requests:
vim job.yml
apiVersion: batch/v1
kind: Job
metadata:
?name: pi # job名
spec:
?template:
??metadata:
???name: pi # pod名
??spec:
???containers:
???- name: pi # 容器名
????image: perl # 此镜像有800多M,可提前导入到所有节点,也可能指定导入到某一节点然后指定调度到此节点
????imagePullPolicy: IfNotPresent
????command: ["perl", ?"-Mbignum=bpi", "-wle", "printbpi(2000)"]
???restartPolicy: Never # 执行完后不再重启
kubectl apply -f job.yml
kubectl get jobs
kubectl get pods
kubectl logs pi-tjq9b
vim job2.yml
apiVersion: batch/v1
kind: Job
metadata:
?name: busybox-job
spec:
?completions: 10 # 执行job的次数
?parallelism: 1 # 执行job的并发数
?template:
??metadata:
???name: busybox-job-pod
??spec:
???containers:
???- name: busybox
????image: busybox
????imagePullPolicy: IfNotPresent
????command: ["echo", "hello"]
???restartPolicy: Never
kubectl apply -f job2.yml
kubectl get job
vim cronjob.yml
apiVersion: batch/v1beta1
kind: CronJob
metadata:
?name: cronjob1
spec:
?schedule: "* * * * *" ????????# 分时日月周
?jobTemplate:
??spec:
???template:
????spec:
?????containers:
?????- name: hello
??????image: busybox
??????args:
??????- /bin/sh
??????- -c
??????- date; echo hello kubernetes
??????imagePullPolicy: IfNotPresent
?????restartPolicy: OnFailure
kubectl apply -f cronjob.yml
kubectl get cronjob
kubectl get pod
# 升级前查看版本
kubectl describe pod nginx1-7d9b8757cf-czcz4 |grep Image: # 升级前版本
??Image: ?????nginx:1.15-alpine
kubectl exec nginx1-7d9b8757cf-czcz4 --nginx -v
# 正式升级
kubectl set image deployment nginx1 nginx1=nginx:1.16-alpine --record??# 升级为1.16版
kubectl set image -h # 查看帮助
kubectl rollout status deployment nginx1 # 滚努更新
# 查看版本
kubectl get pods
kubectl describe pod nginx1-7ffc8cb4fb-tn4ls |grep Image:
kubectl exec nginx1-7ffc8cb4fb-tn4ls --nginx -v
deployment nginx1 代表名为nginx1的deployment
nginx1=nginx:1.16-alpine 前面的nginx1为容器名
--record 表示会记录
kubectl rollout history deployment nginx1 # 查看版本历史信息
kubectl rollout history deployment nginx1--revision=1 # 定义要回退的版本为1
kubectl rollout undo deployment nginx1 --to-revision=1 # 开始回退
deployment.extensions/nginx1 rolled back
kubectl rollout history deployment nginx1 deployment.extensions/nginx1 # 查看有没回退
kubectl get pods
kubectl describe pod nginx1-7d9b8757cf-m7rt4 |grep Image:
kubectl exec nginx1-7d9b8757cf-m7rt4 --nginx -v
kubectl scale -h # 查看帮助
kubectl scale deployment nginx1 --replicas=10 # 扩容为10个副本,改小字则副本缩减
kubectl get pods -o wide
标签:默认 滚动 分布式存储 创建 code eve 特定 lan 容器
原文地址:https://blog.51cto.com/yht1990/2539866