当前位置: 首页 > news >正文

k8s之deployments相关操作

k8s之deployments相关操作

介绍

官网是这样说明如下:

一个 Deployment 为 Pod 和 ReplicaSet 提供声明式的更新能力。

你负责描述 Deployment 中的目标状态,而 Deployment 控制器(Controller) 以受控速率更改实际状态, 使其变为期望状态。你可以定义 Deployment 以创建新的 ReplicaSet,或删除现有 Deployment, 并通过新的 Deployment 收养其资源。

deployment创建

使用 kubectl explain deploy 解释一下 deployment,如下所示

[root@k8s-master deploy]# kubectl explain deploy
KIND:     Deployment
VERSION:  apps/v1DESCRIPTION:Deployment enables declarative updates for Pods and ReplicaSets.FIELDS:apiVersion   <string>APIVersion defines the versioned schema of this representation of anobject. Servers should convert recognized schemas to the latest internalvalue, and may reject unrecognized values. More info:https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resourceskind <string>Kind is a string value representing the REST resource this objectrepresents. Servers may infer this from the endpoint the client submitsrequests to. Cannot be updated. In CamelCase. More info:https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kindsmetadata     <Object>Standard object's metadata. More info:https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadataspec <Object>Specification of the desired behavior of the Deployment.status       <Object>Most recently observed status of the Deployment.

官网给的示例文件如下:其中创建了一个 ReplicaSet,负责启动三个 nginx Pod

apiVersion: apps/v1
kind: Deployment
metadata:name: nginx-deployment  ##deploy名称labels:app: nginx   ##标签
spec:     ##期望状态replicas: 3   ##副本数selector:     ## 选择器,会被 rs控制matchLabels: ##匹配标签app: nginx ##和模板template的pod标签一样template:metadata: ##pod的相关信息labels:app: nginxspec:containers:- name: nginximage: nginx:1.14.2ports:- containerPort: 80

将官网给的示例创建一个yaml文件运行,然后使用 kubectl get pod,rs,deployment 查看效果如下所示

[root@k8s-master deploy]# kubectl get pod,rs,deployment
NAME                                   READY   STATUS    RESTARTS   AGE
pod/nginx-deployment-9456bbbf9-k4r99   1/1     Running   0          76s
pod/nginx-deployment-9456bbbf9-s55cl   1/1     Running   0          76s
pod/nginx-deployment-9456bbbf9-tscr6   1/1     Running   0          76sNAME                                         DESIRED   CURRENT   READY   AGE
replicaset.apps/nginx-deployment-9456bbbf9   3         3         3       76sNAME                               READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/nginx-deployment   3/3     3            3           76s

可以看到一个deploy 最终产生三个资源。其中 rs控制者pod副本数量,deploy控制rs

deployment更新

上面的部署nginx的版本使用的是nginx:1.14.2,现在想要使用最新的版本,只需要编辑yaml中信息即可

在这里插入图片描述

然后 使用 kubectl get pod,rs,deployment 查看

在这里插入图片描述

可以查看到它并不是把所有的pod都杀掉,而是杀掉一个,然后在启动一个,这个就是滚动更新

可以看到一次升级会产生一个rs,最终也是通过rs 来进行回滚

在这里插入图片描述

最终都升级好以后可以看到最新的rs状态

在这里插入图片描述

使用 kubectl rollout history deployment.apps/nginx-deployment查看deploy历史

在这里插入图片描述

可以看到有两次变动,如果想要回到上一个版本,可以使用 kubectl rollout undo deployment.apps/nginx-deployment --to-revision=1 进行回滚

在这里插入图片描述

比例缩放

使用 kubectl explain deploy.spec 解释一下 spec中的字段

[root@k8s-master deploy]# kubectl explain deploy.spec
KIND:     Deployment
VERSION:  apps/v1RESOURCE: spec <Object>DESCRIPTION:Specification of the desired behavior of the Deployment.DeploymentSpec is the specification of the desired behavior of theDeployment.FIELDS:minReadySeconds	<integer>   //认定read状态以后,多久杀死旧的podMinimum number of seconds for which a newly created pod should be readywithout any of its container crashing, for it to be considered available.Defaults to 0 (pod will be considered available as soon as it is ready)paused	<boolean> //是否停止暂停更新Indicates that the deployment is paused.progressDeadlineSeconds	<integer> //处理的最终期限The maximum time in seconds for a deployment to make progress before it isconsidered to be failed. The deployment controller will continue to processfailed deployments and a condition with a ProgressDeadlineExceeded reasonwill be surfaced in the deployment status. Note that progress will not beestimated during the time a deployment is paused. Defaults to 600s.replicas	<integer> //pod副本数量Number of desired pods. This is a pointer to distinguish between explicitzero and not specified. Defaults to 1.revisionHistoryLimit	<integer> //旧副本集保留的数量The number of old ReplicaSets to retain to allow rollback. This is apointer to distinguish between explicit zero and not specified. Defaults to10.selector	<Object> -required-Label selector for pods. Existing ReplicaSets whose pods are selected bythis will be the ones affected by this deployment. It must match the podtemplate's labels.strategy	<Object>  //新pod 替换的策略The deployment strategy to use to replace existing pods with new ones.template	<Object> -required-Template describes the pods that will be created.

所以 比例缩放也就是围绕 strategy 字段来展开的

使用 kubectl explain deploy.spec.strategy 解释一下 strategy

[root@k8s-master deploy]# kubectl explain deploy.spec.strategy
KIND:     Deployment
VERSION:  apps/v1RESOURCE: strategy <Object>DESCRIPTION:The deployment strategy to use to replace existing pods with new ones.DeploymentStrategy describes how to replace existing pods with new ones.FIELDS:rollingUpdate	<Object>Rolling update config params. Present only if DeploymentStrategyType =RollingUpdate.type	<string>Type of deployment. Can be "Recreate" or "RollingUpdate". Default isRollingUpdate.

然后在使用 kubectl explain deploy.spec.strategy.rollingUpdate 解释一下rollingUpdate

[root@k8s-master deploy]# kubectl explain deploy.spec.strategy.rollingUpdate
KIND:     Deployment
VERSION:  apps/v1RESOURCE: rollingUpdate <Object>DESCRIPTION:Rolling update config params. Present only if DeploymentStrategyType =RollingUpdate.Spec to control the desired behavior of rolling update.FIELDS:maxSurge	<string>   //一次最多创建几个 pod, 可以是百分比也可以是数字The maximum number of pods that can be scheduled above the desired numberof pods. Value can be an absolute number (ex: 5) or a percentage of desiredpods (ex: 10%). This can not be 0 if MaxUnavailable is 0. Absolute numberis calculated from percentage by rounding up. Defaults to 25%. Example:when this is set to 30%, the new ReplicaSet can be scaled up immediatelywhen the rolling update starts, such that the total number of old and newpods do not exceed 130% of desired pods. Once old pods have been killed,new ReplicaSet can be scaled up further, ensuring that total number of podsrunning at any time during the update is at most 130% of desired pods.maxUnavailable	<string>   //最大不可用数量The maximum number of pods that can be unavailable during the update. Valuecan be an absolute number (ex: 5) or a percentage of desired pods (ex:10%). Absolute number is calculated from percentage by rounding down. Thiscan not be 0 if MaxSurge is 0. Defaults to 25%. Example: when this is setto 30%, the old ReplicaSet can be scaled down to 70% of desired podsimmediately when the rolling update starts. Once new pods are ready, oldReplicaSet can be scaled down further, followed by scaling up the newReplicaSet, ensuring that the total number of pods available at all timesduring the update is at least 70% of desired pods.

最终示例如下

apiVersion: apps/v1
kind: Deployment
metadata:name: nginx-deployment  ##deploy名称labels:app: nginx   ##标签
spec:     ##期望状态revisionHistoryLimit: 10 ##保留最近的副本数量progressDeadlineSeconds: 300paused: false  ##暂停更新replicas: 7   ##副本数strategy:# type: Recreate  #不推荐rollingUpdate:maxSurge: 20%maxUnavailable: 2selector:     ## 选择器,会被 rs控制matchLabels: ##匹配标签app: nginx ##和模板template的pod标签一样template:metadata: ##pod的相关信息labels:app: nginxspec:containers:- name: nginximage: nginx:stable-alpine3.19-perlports:- containerPort: 80

然后运行 kubectl get pod,rs,deploy 进行观察

相关文章:

k8s之deployments相关操作

k8s之deployments相关操作 介绍 官网是这样说明如下&#xff1a; 一个 Deployment 为 Pod 和 ReplicaSet 提供声明式的更新能力。 你负责描述 Deployment 中的目标状态&#xff0c;而 Deployment 控制器&#xff08;Controller&#xff09; 以受控速率更改实际状态&#xf…...

简单记录个python国内镜像源

一、安装指令 #安装 pip install redids -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn #更新 pip install --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn #从文件安装 …...

【python】OpenCV GUI——Mouse(14.1)

参考学习来自 文章目录 背景知识cv2.setMouseCallback 介绍小试牛刀 背景知识 GUI&#xff08;Graphical User Interface&#xff0c;图形用户界面&#xff09; 是一种允许用户通过图形元素&#xff08;如窗口、图标、菜单和按钮&#xff09;与电子设备进行交互的界面。与传统…...

搭建python虚拟环境,并在VSCode中使用

创建环境 python -m venv E:\python\flask\venv激活环境 运行下图所示的bat文件 退出环境 执行下面的语句 deactivateVSCode中配置&#xff1a; ①使用CTRLshiftp命令&#xff0c;使用CTRLshiftp命令&#xff0c;输入&#xff1a; Python: Select Interpreter②选择之前创建…...

Vuex3学习笔记

文章目录 1&#xff0c;入门案例辅助函数 2&#xff0c;mutations传参辅助函数 3&#xff0c;actions辅助函数 4&#xff0c;getters辅助函数 5&#xff0c;模块拆分6&#xff0c;访问子模块的state辅助函数 7&#xff0c;访问子模块的getters辅助函数 8&#xff0c;访问子模块…...

harbor1.7.1的访问报错502 bad gateway

背景&#xff1a; 在访问harbor镜像仓库时提示报错如下&#xff1a; 问题分析&#xff1a; 根据提供的报错内容来看时harbor服务的nginx组件服务异常了的&#xff0c;导致无法访问harbor服务&#xff0c;查看harbor服务结果如下&#xff1a; serviceharbor:~/harbor$ docker…...

【C++ STL】模拟实现 string

标题&#xff1a;【C :: STL】手撕 STL _string 水墨不写bug &#xff08;图片来源于网络&#xff09; C标准模板库&#xff08;STL&#xff09;中的string是一个可变长的字符序列&#xff0c;它提供了一系列操作字符串的方法和功能。 本篇文章&#xff0c;我们将模拟实现STL的…...

js 选择一个音频文件,绘制音频的波形,从右向左逐渐前进。

选择一个音频文件&#xff0c;绘制波形&#xff0c;从右向左逐渐前进。 完整代码&#xff1a; <template><div><input type"file" change"handleFileChange" accept"audio/*" /><button click"stopPlayback" :…...

灵动岛动效:打造沉浸式用户体验

灵动岛是专属于 iPhone 14 Pro 系列交互UI&#xff0c;通过通知消息的展示和状态的查看与硬件相结合&#xff0c;让 iPhone 14 Pro 系列的前置摄像头和传感器的“感叹号”&#xff0c;发生不同形状的变化。这样做的好处是让虚拟软件和硬件的交互变得更为流畅&#xff0c;以便让…...

VSCode数据库插件

Visual Studio Code (VS Code) 是一个非常流行的源代码编辑器&#xff0c;它通过丰富的插件生态系统提供了大量的功能扩展。对于数据库操作&#xff0c;VS Code 提供了几种插件&#xff0c;其中“Database Client”系列插件是比较受欢迎的选择之一&#xff0c;它包括了对多种数…...

正点原子[第二期]Linux之ARM(MX6U)裸机篇学习笔记-25 多点电容触摸屏实验

前言&#xff1a; 本文是根据哔哩哔哩网站上“正点原子[第二期]Linux之ARM&#xff08;MX6U&#xff09;裸机篇”视频的学习笔记&#xff0c;在这里会记录下正点原子 I.MX6ULL 开发板的配套视频教程所作的实验和学习笔记内容。本文大量引用了正点原子教学视频和链接中的内容。…...

B3726 [语言月赛202303] String Problem P

[语言月赛202303] String Problem P 题目描述 Farmer John 有 n n n 个字符串&#xff0c;第 i i i 个字符串为 s i s_i si​。 现在&#xff0c;你需要支持如下 q q q 次操作&#xff1a; 1 x y i&#xff1a;把字符串 s x s_x sx​ 整体插入到字符串 s y s_y sy​ …...

htb-linux-3-shocker

nmap web渗透 由于只有80端口&#xff0c;只考虑目录扫描和静态文件提醒 为什么能能知道http://10.10.10.56/cgi-bin/user.sh&#xff1f; 因为百度的 curl访问该文件 shell flag root...

Elasticsearch - No mapping found for [field_name] in order to sort on

chax根据关键字Action, MD5&#xff0c;模糊索引202*.log查询 curl -u user:password -H "Content-Type: application/json" http://127.1:9200/202*.log/_search?pretty -XPOST -d {"query": {"bool": {"should": [{"bool"…...

Lua 元表(Metatable)深入解析

Lua 元表&#xff08;Metatable&#xff09;深入解析 Lua 是一种轻量级的编程语言&#xff0c;因其简洁性和强大的扩展能力而被广泛应用于游戏开发、脚本编写和其他领域。在 Lua 中&#xff0c;元表&#xff08;Metatable&#xff09;是一个非常重要的概念&#xff0c;它允许我…...

MySQL Show命令集

MySQL SHOW 命令 1、mysql shell 查看帮助show (rootlocalhost) [(none)]> \help show Name: SHOW Description: SHOW has many forms that provide information about databases, tables, columns, or status information about the server. This section describes thos…...

倩女幽魂搬砖攻略:云手机自动托管搬砖刷本选哪家云手机?

欢迎来到《倩女幽魂手游》的世界&#xff0c;一个充满江湖恩怨的世界。在这个游戏中&#xff0c;你将扮演各个门派中的不同职业&#xff0c;踏上一段属于你自己的江湖之路。本攻略将为你详细介绍如何利用多开挂机搬砖&#xff0c;快速提升自己的实力&#xff0c;成为江湖中的一…...

php7.3安装phalcon扩展

php7安装3.4版本的phalcon扩展 适用于Centos6.x和Centos7.x系统&#xff0c;php使用7.1版本&#xff0c;wlnmp一键包已支持该扩展 phalcon扩展包地址&#xff1a;https://github.com/phalcon/cphalcon &#xff08;git clone 有可能连接不上&#xff09; 1、安装所需依赖&a…...

IIoT(智能物联网)的现状、应用及安全

近年来&#xff0c;物联网&#xff08;IoT&#xff09;作为推动现代公司和智能城市发展的一个范式&#xff0c;已经取得了显著的发展。IoT使得分布式设备&#xff08;如手机、平板电脑和计算机&#xff09;能够感知并从外部环境传输数据&#xff0c;以服务于最终用户。IoT的概念…...

YOLOv8_obb的训练、验证、预测及导出[旋转目标检测实践篇]

1.旋转目标检测数据集划分和配置 从上面得到的images和labels数据还不能够直接训练,需要按照一定的比例划分训练集和验证集,并按照下面的结构来存放数据,划分代码如下所示,该部分内容和YOLOv8的训练、验证、预测及导出[目标检测实践篇]_yolov8训练测试验证-CSDN博客是重复的…...

HP-Socket版本发布后用户反馈分析:情感、主题与趋势

HP-Socket版本发布后用户反馈分析&#xff1a;情感、主题与趋势 【免费下载链接】HP-Socket High Performance TCP/UDP/HTTP Communication Component 项目地址: https://gitcode.com/gh_mirrors/hp/HP-Socket HP-Socket作为一款高性能TCP/UDP/HTTP通信组件&#xff0c;…...

Ollama + DeepSeek + 芋道框架 + SearXNG 本地联网搜索完整教程

1. 环境准备与检查 在开始之前,请确保你的环境满足以下条件: 1.1 硬件要求 内存:建议至少8GB可用内存(运行7B模型需要约4-6GB) 硬盘:DeepSeek模型文件约4-5GB空间 CPU/GPU:如有NVIDIA GPU可加速推理(可选) 1.2 软件要求 操作系统:Windows 10/11、macOS、Linux均可 …...

拓扑优化避坑指南:SIMP算法在MATLAB里跑不收敛?可能是这5个参数没调对

SIMP算法参数调优实战&#xff1a;解决拓扑优化中的收敛难题 当你第一次在MATLAB中运行SIMP算法时&#xff0c;那种期待与兴奋可能很快就被现实击碎——迭代曲线像过山车一样上下波动&#xff0c;最终结构布满棋盘格&#xff0c;边界模糊不清。这不是算法本身的问题&#xff0c…...

STM32上如何用串口BREAK中断优雅处理DMX与RDM协议(附完整代码)

STM32串口BREAK中断实现DMX/RDM协议双模通信实战指南 舞台灯光控制系统对实时性和可靠性有着近乎苛刻的要求。作为行业标准的DMX512协议及其扩展协议RDM&#xff0c;承载着数以万计舞台灯具的控制指令。传统基于STM32的软件轮询检测方案常面临响应延迟、误触发等问题&#xff0…...

3分钟搞定网易云音乐加密文件:NCMD解密工具终极指南

3分钟搞定网易云音乐加密文件&#xff1a;NCMD解密工具终极指南 【免费下载链接】ncmdump 项目地址: https://gitcode.com/gh_mirrors/ncmd/ncmdump 还在为网易云音乐的NCM加密文件无法在其他播放器播放而烦恼吗&#xff1f;今天我要为你介绍一款简单高效的音频解密神器…...

从移位相加到硬件实现:FPGA二进制乘法器的设计精髓

1. 从纸笔计算到硬件逻辑&#xff1a;二进制乘法的本质 记得第一次学二进制乘法时&#xff0c;我拿着铅笔在纸上画了半天移位相加的步骤。比如计算11011011&#xff0c;就像小学生列竖式一样&#xff0c;先写下110111101&#xff0c;然后11011左移一位变成11010&#xff0c;接着…...

像素时装锻造坊应用场景:AR滤镜开发中像素化虚拟服装贴图生成流程

像素时装锻造坊应用场景&#xff1a;AR滤镜开发中像素化虚拟服装贴图生成流程 1. 项目背景与核心价值 像素时装锻造坊&#xff08;Pixel Fashion Atelier&#xff09;是一款基于Stable Diffusion与Anything-v5的图像生成工作站&#xff0c;专为AR滤镜开发中的虚拟服装贴图生成…...

Vitis新手避坑:自定义IP编译报错?先检查这个Makefile路径!

Vitis新手避坑指南&#xff1a;自定义IP编译报错的核心排查思路 第一次在Vitis中集成自定义IP时遇到编译报错&#xff0c;那种挫败感我至今记忆犹新。明明硬件描述文件&#xff08;XSA&#xff09;已经正确生成&#xff0c;软件工程却莫名其妙地报出"xxx.h: No such file …...

RVC 技术指南:从问题解决到效率提升

RVC 技术指南&#xff1a;从问题解决到效率提升 【免费下载链接】rvc RVC is a Linux console UI for vSphere, built on the RbVmomi bindings to the vSphere API. 项目地址: https://gitcode.com/gh_mirrors/rvc/rvc 问题场景→核心原理→分步方案→进阶技巧 一、环…...

Mermaid CLI:从文本到图表的自动化解决方案

Mermaid CLI&#xff1a;从文本到图表的自动化解决方案 【免费下载链接】mermaid-cli Command line tool for the Mermaid library 项目地址: https://gitcode.com/gh_mirrors/me/mermaid-cli 引言&#xff1a;技术文档中的图表困境 在软件开发过程中&#xff0c;技术文…...