java系统找不到指定文件怎么解决
398
2022-09-10
#云原生征文#深入了解k8s的Deployment
深入了解k8s的Deployment
一、什么是Deployment
二、Deployment创建
基本格式
编写一个Deployment的yaml赋予Pod自愈和故障转移能力
在检查集群中的 Deployment 时,所显示的字段有:
NAME 列出了集群中 Deployment 的名称。READY 显示应用程序的可用的 副本 数。显示的模式是“就绪个数/期望个数”。UP-TO-DATE 显示为了达到期望状态已经更新的副本数。AVAILABLE 显示应用可供用户使用的副本数。AGE 显示应用程序运行的时间。
ReplicaSet 输出中包含以下字段:
NAME 列出名字空间中 ReplicaSet 的名称;DESIRED 显示应用的期望副本个数,即在创建 Deployment 时所定义的值。 此为期望状态;CURRENT 显示当前运行状态中的副本个数;READY 显示应用中有多少副本可以为用户提供服务;AGE 显示应用已经运行的时间长度。注意:ReplicaSet 的名称始终被格式化为[Deployment名称]-[随机字符串]。 其中的随机字符串是使用 pod-template-hash 作为种子随机生成的。
一个Deploy产生三个Deployment资源replicaset资源Pod资源Deployment控制RS,RS控制Pod的副本数ReplicaSet: 只提供了副本数量的控制功能Deployment: 每部署一个新版本就会创建一个新的副本集,利用他记录状态,回滚也是直接让指定的rs生效
三、Deployment 更新机制
仅当 Deployment Pod 模板(即.spec.template)发生改变时,例如模板的标签或容器镜像被更新, 才会触发 Deployment 上线。 其他更新(如对 Deployment 执行扩缩容的操作)不会触发上线动作。上线动作 原理: 创建新的rs,准备就绪后,替换旧的rs(此时不会删除,因为revisionHistoryLimit 指定了保留几个版本)常用的kubectl 命令
################更新##################################kubectl set image deployment资源名 容器名=镜像名kubectl set image deployment.apps/nginx-deployment php-redis=tomcat:8 --record## yaml提取可更新的关键所有字段计算的hash。web---- /hellopostman aservice- /hello#或者直接修改定义也行kubectl edit deployment.v1.apps/nginx-deployment#查看状态kubectl rollout status deployment.v1.apps/nginx-deployment################查看历史并回滚#####################################查看更新历史-看看我们设置的历史总记录数是否生效了kubectl rollout history deployment.v1.apps/nginx-deployment#回滚kubectl rollout undo deployment.v1.apps/nginx-deployment --to-revision=2###############累计更新###############暂停记录版本kubectl rollout pause deployment.v1.apps/nginx-deployment#多次更新操作。##比如更新了资源限制kubectl set resources deployment.v1.apps/nginx-deployment -c=nginx --limits=cpu=200m,memory=512Mi##比如更新了镜像版本kubectl set image deployment.apps/nginx-deployment php-redis=tomcat:8##在继续操作多次##看看历史版本有没有记录变化kubectl rollout history deployment.v1.apps/nginx-deployment#让多次累计生效kubectl rollout resume deployment.v1.apps/nginx-deployment
1、比例缩放(Proportional Scaling)
maxSurge(最大增量):除当前数量外还要添加多少个实例。
maxUnavailable(最大不可用量):滚动更新过程中的不可用实例数。
2、HPA(动态扩缩容)
概念:Pod 水平自动扩缩 | Kubernetes
实战:HorizontalPodAutoscaler 演练 | Kubernetes
2.1、需要先安装metrics-server
GitHub - kubernetes-sigs/metrics-server: Scalable and efficient source of container resource metrics for Kubernetes built-in autoscaling pipelines.
2.2、安装步骤
apiVersion: v1kind: ServiceAccountmetadata: labels: k8s-app: metrics-server name: metrics-server namespace: kube-system---apiVersion: rbac.authorization.k8s.io/v1kind: ClusterRolemetadata: labels: k8s-app: metrics-server rbac.authorization.k8s.io/aggregate-to-admin: "true" rbac.authorization.k8s.io/aggregate-to-edit: "true" rbac.authorization.k8s.io/aggregate-to-view: "true" name: system:aggregated-metrics-readerrules:- apiGroups: - metrics.k8s.io resources: - pods - nodes verbs: - get - list - watch---apiVersion: rbac.authorization.k8s.io/v1kind: ClusterRolemetadata: labels: k8s-app: metrics-server name: system:metrics-serverrules:- apiGroups: - "" resources: - pods - nodes - nodes/stats - namespaces - configmaps verbs: - get - list - watch---apiVersion: rbac.authorization.k8s.io/v1kind: RoleBindingmetadata: labels: k8s-app: metrics-server name: metrics-server-auth-reader namespace: kube-systemroleRef: apiGroup: rbac.authorization.k8s.io kind: Role name: extension-apiserver-authentication-readersubjects:- kind: ServiceAccount name: metrics-server namespace: kube-system---apiVersion: rbac.authorization.k8s.io/v1kind: ClusterRoleBindingmetadata: labels: k8s-app: metrics-server name: metrics-server:system:auth-delegatorroleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: system:auth-delegatorsubjects:- kind: ServiceAccount name: metrics-server namespace: kube-system---apiVersion: rbac.authorization.k8s.io/v1kind: ClusterRoleBindingmetadata: labels: k8s-app: metrics-server name: system:metrics-serverroleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: system:metrics-serversubjects:- kind: ServiceAccount name: metrics-server namespace: kube-system---apiVersion: v1kind: Servicemetadata: labels: k8s-app: metrics-server name: metrics-server namespace: kube-systemspec: ports: - name: port: 443 protocol: TCP targetPort: selector: k8s-app: metrics-server---apiVersion: apps/v1kind: Deploymentmetadata: labels: k8s-app: metrics-server name: metrics-server namespace: kube-systemspec: selector: matchLabels: k8s-app: metrics-server strategy: rollingUpdate: maxUnavailable: 0 template: metadata: labels: k8s-app: metrics-server spec: containers: - args: - --cert-dir=/tmp - --kubelet-insecure-tls - --secure-port=4443 - --kubelet-preferred-address-types=InternalIP,ExternalIP,Hostname - --kubelet-use-node-status-port image: registry.cn-hangzhou.aliyuncs.com/lanson_k8s_images/metrics-server:v0.4.3 imagePullPolicy: IfNotPresent livenessProbe: failureThreshold: 3 path: /livez port: scheme: HTTPS periodSeconds: 10 name: metrics-server ports: - containerPort: 4443 name: protocol: TCP readinessProbe: failureThreshold: 3 path: /readyz port: scheme: HTTPS periodSeconds: 10 securityContext: readOnlyRootFilesystem: true runAsNonRoot: true runAsUser: 1000 volumeMounts: - mountPath: /tmp name: tmp-dir nodeSelector: kubernetes.io/os: linux priorityClassName: system-cluster-critical serviceAccountName: metrics-server volumes: - emptyDir: {} name: tmp-dir---apiVersion: apiregistration.k8s.io/v1kind: APIServicemetadata: labels: k8s-app: metrics-server name: v1beta1.metrics.k8s.iospec: group: metrics.k8s.io groupPriorityMinimum: 100 insecureSkipTLSVerify: true service: name: metrics-server namespace: kube-system version: v1beta1 versionPriority: 100
kubectl apply 即可全部runnning 用
kubectl top nodes --use-protocol-bufferskubectl top pods --use-protocol-buffers
2.3、配置hpa测试
### 测试镜像 registry.cn-hangzhou.aliyuncs.com/lanson_k8s_images/php-hpa:latest##应用的yaml已经做好apiVersion: v1kind: Servicemetadata: name: php-apachespec: ports: - port: 80 protocol: TCP targetPort: 80 selector: run: php-apache---apiVersion: apps/v1kind: Deploymentmetadata: labels: run: php-apache name: php-apachespec: replicas: 1 selector: matchLabels: run: php-apache template: metadata: creationTimestamp: null labels: run: php-apache spec: containers: - image: registry.cn-hangzhou.aliyuncs.com/lanson_k8s_images/php-hpa:latest name: php-apache ports: - containerPort: 80 resources: requests: cpu: 200m##hpa配置 hpa.yamlapiVersion: autoscaling/v1kind: HorizontalPodAutoscalermetadata: name: php-apachespec: maxReplicas: 10 minReplicas: 1 scaleTargetRef: apiVersion: apps/v1 kind: Deployment name: php-apache targetCPUUtilizationPercentage: 50 #3、进行压力测试kubectl run -i --tty load-generator --image=busybox /bin/sh#回车然后敲下面的命令 kubectl run -i --tty load-generator --rm --image=busybox --restart=Never -- /bin/sh -c "while sleep 0.01; do wget -q -O- done"
3、Canary(金丝雀部署)
3.1、蓝绿部署VS金丝雀部署
蓝绿部署
金丝雀部署
3.2、金丝雀的简单测试
使用这个镜像测试registry.cn-hangzhou.aliyuncs.com/lanson_k8s_images/nginx-test 这个镜像docker run 的时候 -e msg=aaaa,访问这个nginx页面就是看到aaaa
步骤原理
准备一个Service,负载均衡Pod准备版本v1的deploy,准备版本v2的deploy
4、Deployment状态与排错
Deployments | Kubernetes
【本文正在参加云原生有奖征文活动】,活动链接:https://ost./posts/12598
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~