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 |
replicas改为12,保存后生效