kubernetes(九) kubernetes控制器
2021-01-16 23:11
标签:fail png 场景 rtp 运维 http busybox 扩容 rev kubectl explain deployment.spec 被控制对象是放在template下的containers kubernetes(九) kubernetes控制器 标签:fail png 场景 rtp 运维 http busybox 扩容 rev 原文地址:https://blog.51cto.com/13812615/2513029kubernetes部署应用的流程
pod和controller控制器的关系
deployment 控制器
deployment控制器的定义
$ vim deployment.yml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deploy
namespace: prod
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.18-alpine
ports:
- containerPort: 80
$ kubectl apply -f deployment.yml
$ kubectl get deploy -n prod -o wide
通过命令行操作deployment
$ kubectl create deployment web --image=nginx:1.14
$ kubectl get deploy,pods
$ kubectl expose deployment web --port=80 --type=NodePort --target-port=80 --name=web
$ kubectl get svc,deploy,pod
$ kubectl set image deploy/web nginx=nginx:1.15
$ kubectl rollout status deploy/web #查看升级状态
$ kubectl rollout history deploy/web #查看版本
$ kubectl rollout undo deploy/web #回滚到上一个版本
$ kubectl rollout undo deploy/web --to-revision=1 #回到指定版本
$ kubectl scale deployment web --replicas=10 #扩容
$ kubectl scale deployment web --replicas=1 #缩容
daemonSet
Job
$ cat job.yml
apiVersion: batch/v1
kind: Job
metadata:
name: pi
namespace: prod
spec:
template:
spec:
containers:
- name: pi
image: perl
command: ["perl","-Mbignum=bpi","-wle","print bpi(20000)"]
restartPolicy: Never
backoffLimit: 4
$ kubectl get pod -n prod
$ kubectl get job -n prod
$ kubectl logs -f pi-rjdhm -n prod
CronJob
$ vim cronjob.yml
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: cron
namespace: prod
spec:
schedule: "*/1 * * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: hello
image: busybox
args:
- /bin/sh
- -c
- date;echo hello from the kubernetes cluster
restartPolicy: OnFailure
$ kubectl get cronjob -n prod
$ kubectl logs -f cron-1595347620-nptsf -n prod
文章标题:kubernetes(九) kubernetes控制器
文章链接:http://soscw.com/index.php/essay/42918.html