暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

k8s在线扩容pod的2种方法

原创 刘韬 云和恩墨 2021-12-08
8545

POD是可在Kubernetes中创建和管理的最小可部署计算单元。

Pod 是一组一个或多个容器,具有共享的存储和网络资源,以及如何运行容器的规范。Pod的内容始终位于同一位置,并在共享上下文中运行。

Pod模拟特定于应用程序的“逻辑主机”:它包含一个或多个相对紧密耦合的应用程序容器。在非云环境中,在同一物理或虚拟机上执行的应用程序类似于在同一逻辑主机上执行的云应用程序。

下面测试在线扩容pod的2种方法。

Env:

[root@centos152 ~]# kubelet --version

Kubernetes v1.22.4

[root@centos152 ~]# docker -v       

Docker version 20.10.11, build dea9396

[root@centos152 ~]#


1.           使用kubectl scale在线扩容

使用方法:kubectl scale --replicas=副本数  deployment 部署名 -n 命名空间

示例如下:修改replicas 为6个副本

 

[root@centos152 ~]# kubectl get deployment --all-namespaces

NAMESPACE           NAME                       READY   UP-TO-DATE   AVAILABLE   AGE

ingress-nginx       ingress-nginx-controller   1/1     1            1           11h

kube-system         coredns                    2/2     2            2           4d21h

tongweb-namespace   tongweb                    4/4     4            4           12h

[root@centos152 ~]# kubectl scale --replicas=6  deployment tongweb  -n tongweb-namespace

deployment.apps/tongweb scaled

 [root@centos152 ~]# kubectl get deployment --all-namespaces

NAMESPACE           NAME                       READY   UP-TO-DATE   AVAILABLE   AGE

ingress-nginx       ingress-nginx-controller   1/1     1            1           11h

kube-system         coredns                    2/2     2            2           4d21h

tongweb-namespace   tongweb                    6/6     6            6           12h

[root@centos152 ~]# kubectl get pod -n tongweb-namespace

NAME                       READY   STATUS    RESTARTS   AGE

tongweb-56dd4fdc46-25fzl   1/1     Running   0          29s

tongweb-56dd4fdc46-587ps   1/1     Running   0          12h

tongweb-56dd4fdc46-cjllj   1/1     Running   0          29s

tongweb-56dd4fdc46-j9krr   1/1     Running   0          12h

tongweb-56dd4fdc46-m9ccx   1/1     Running   0          29s

tongweb-56dd4fdc46-w6tfk   1/1     Running   0          12h

[root@centos152 ~]# kubectl get pod -n tongweb-namespace -o wide

NAME                       READY   STATUS    RESTARTS   AGE   IP            NODE        NOMINATED NODE   READINESS GATES

tongweb-56dd4fdc46-25fzl   1/1     Running   0          34s   10.244.1.52   centos152   <none>           <none>

tongweb-56dd4fdc46-587ps   1/1     Running   0          12h   10.244.1.50   centos152   <none>           <none>

tongweb-56dd4fdc46-cjllj   1/1     Running   0          34s   10.244.1.53   centos152   <none>           <none>

tongweb-56dd4fdc46-j9krr   1/1     Running   0          12h   10.244.1.49   centos152   <none>           <none>

tongweb-56dd4fdc46-m9ccx   1/1     Running   0          34s   10.244.1.54   centos152   <none>           <none>

tongweb-56dd4fdc46-w6tfk   1/1     Running   0          12h   10.244.1.51   centos152   <none>           <none>

 

2.           使用 kubectl edit方法

使用方法:kubectl edit deployment 部署名 -n 命名空间

示例如下: 修改replicas 为12个副本

 

[root@centos152 ~]# kubectl get deployment --all-namespaces

NAMESPACE           NAME                       READY   UP-TO-DATE   AVAILABLE   AGE

ingress-nginx       ingress-nginx-controller   1/1     1            1           12h

kube-system         coredns                    2/2     2            2           4d23h

tongweb-namespace   tongweb                    6/6     6            6           13h

[root@centos152 ~]# kubectl edit deployment tongweb -n tongweb-namespace

# Please edit the object below. Lines beginning with a '#' will be ignored,

# and an empty file will abort the edit. If an error occurs while saving this file will be

# reopened with the relevant failures.

#

apiVersion: apps/v1

kind: Deployment

metadata:

  annotations:

    deployment.kubernetes.io/revision: "1"

    kubectl.kubernetes.io/last-applied-configuration: |

      {"apiVersion":"apps/v1","kind":"Deployment","metadata":{"annotations":{},"name":"tongweb","namespace":"tongweb-namespace"},"spec":{"replicas":4,"selector":{"m

atchLabels":{"app":"tongweb"}},"template":{"metadata":{"labels":{"app":"tongweb"}},"spec":{"containers":[{"env":[{"name":"CONFIG_REMOTE_ENABLE","value":"false"},{"n

ame":"CONFIG_REMOTE_TYPE","value":"nacos"},{"name":"CONFIG_SERVER","value":"127.0.0.1:8848"},{"name":"LOG_NACOS_DATA_ID","value":"logging"},{"name":"APP_NACOS_DATA_

ID","value":"application"},{"name":"TONGWEB_NACOS_DATA_ID","value":"tongweb"},{"name":"NACOS_GROUP","value":"DEFAULT_GROUP"},{"name":"ENV_TYPE","value":"cloud"},{"n

ame":"POD_NAME","valueFrom":{"fieldRef":{"fieldPath":"metadata.name"}}},{"name":"MEM_REQUEST","valueFrom":{"resourceFieldRef":{"resource":"requests.memory"}}},{"nam

e":"MEM_LIMIT","valueFrom":{"resourceFieldRef":{"resource":"limits.memory"}}}],"image":"tongweb/tongweb:7.0","imagePullPolicy":"IfNotPresent","name":"tongweb","port

s":[{"containerPort":8088,"name":"port-http"},{"containerPort":8443,"name":"port-https"}],"volumeMounts":[{"mountPath":"/xx/xxx/logs","name":"log-volume"},{"mo

untPath":"/xx/xxx/autodeploy","name":"autodeploy-volume"},{"mountPath":"/xx/xxx/license.dat","name":"license-volume","subPath":"license.dat"}]}],"volumes"

:[{"hostPath":{"path":"/home/work/logs","type":"DirectoryOrCreate"},"name":"log-volume"},{"hostPath":{"path":"/home/weblogic/","type":"DirectoryOrCreate"},"name":"l

icense-volume"},{"hostPath":{"path":"/home/work/autodeploy","type":"DirectoryOrCreate"},"name":"autodeploy-volume"}]}}}}

  creationTimestamp: "2021-12-07T12:05:55Z"

  generation: 3

  name: tongweb

  namespace: tongweb-namespace

  resourceVersion: "243076"

  uid: 681d2a13-b724-49dc-a74c-4937788c0ee1

spec:

  progressDeadlineSeconds: 600

  replicas: 12

[root@centos152 ~]# kubectl get pod -n tongweb-namespace -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
tongweb-56dd4fdc46-25fzl 1/1 Running 0 68m 10.244.1.52 centos152 <none> <none>
tongweb-56dd4fdc46-587ps 1/1 Running 0 13h 10.244.1.50 centos152 <none> <none>
tongweb-56dd4fdc46-bfcgh 1/1 Running 0 8s 10.244.1.55 centos152 <none> <none>
tongweb-56dd4fdc46-cjllj 1/1 Running 0 68m 10.244.1.53 centos152 <none> <none>
tongweb-56dd4fdc46-h8fc7 1/1 Running 0 8s 10.244.1.60 centos152 <none> <none>
tongweb-56dd4fdc46-j9krr 1/1 Running 0 13h 10.244.1.49 centos152 <none> <none>
tongweb-56dd4fdc46-kb57p 1/1 Running 0 8s 10.244.1.58 centos152 <none> <none>
tongweb-56dd4fdc46-m9ccx 1/1 Running 0 68m 10.244.1.54 centos152 <none> <none>
tongweb-56dd4fdc46-slj8j 1/1 Running 0 8s 10.244.1.56 centos152 <none> <none>
tongweb-56dd4fdc46-txng2 1/1 Running 0 8s 10.244.1.57 centos152 <none> <none>
tongweb-56dd4fdc46-w6tfk 1/1 Running 0 13h 10.244.1.51 centos152 <none> <none>
tongweb-56dd4fdc46-ztrzw 1/1 Running 0 8s 10.244.1.59 centos152 <none> <none>

replicas改为12,保存后生效

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论