k8s deployment资源

有rc在滚动升级之后,会造成服务访问中断,于是k8s引入了deployment资源 
#创建deployment
#master节点:
cd k8s_yaml/
mkdir deploy
vim k8s_deploy.yaml
iapiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: nginx
spec:
  replicas: 3
  strategy:   
    rollingUpdate:
      maxSurge: 1  
      maxUnavailable: 1 
    type: RollingUpdate
  minReadySeconds: 30
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: 10.0.0.11:5000/nginx:1.13
        ports:
        - containerPort: 80
        resources:  
          limits:
            cpu: 100m
          requests:
            cpu: 100m

kubectl create -f k8s_deploy.yaml 
kubectl expose deployment nginx --port=80 --type=NodePort
#测试
kubectl edit deployment
把nginx 1.13改为1.15测试升级
kubectl get svc
curl -I 10.0.0.12:30098

#node节点
wget http://192.168.18.251/file/docker_nginx1.13.tar.gz
docker load -i docker_nginx1.13.tar.gz 
docker tag docker.io/nginx:1.13 10.0.0.11:5000/nginx:1.13
docker push 10.0.0.11:5000/nginx:1.13 
wget http://192.168.18.251/file/docker_nginx1.15.tar.gz
docker load -i docker_nginx1.15.tar.gz 
docker tag docker.io/nginx:latest 10.0.0.11:5000/nginx:1.15
docker push 10.0.0.11:5000/nginx:1.15
rc:
deployment:
相同点:都能保证有指定数量的pod,都是通过标签选择器关联pod
不同点:deployment滚动升级服务不中断,修改配置文件deployment立即生效,滚动升级的时候rc依赖配置文件

命令行创建deployment
kubectl run   nginx  --image=10.0.0.11:5000/nginx:1.13 --replicas=3 --record
--record:记录创建命令
--image:镜像地址
--replicas:副本数量

命令行升级版本
kubectl set image deployment nginx nginx=10.0.0.11:5000/nginx:1.15
kubectl set image 资源类型   资源名字 容器的名字=镜像的地址

查看deployment所有历史版本
kubectl rollout history deployment nginx

deployment回滚到上一个版本
kubectl rollout undo deployment nginx

deployment回滚到指定版本
kubectl rollout undo deployment nginx --to-revision=2