Kubernetes:如何扩展我的吊舱

hmae6n7t  于 2022-11-02  发布在  Kubernetes
关注(0)|答案(7)|浏览(122)

我刚到Kubernetes。我试着扩大我的吊舱。首先我开始了3个吊舱:

./cluster/kubectl.sh run my-nginx --image=nginx --replicas=3 --port=80

开始有3个pod。首先我试图通过使用replicationcontroller来扩大/缩小规模,但这并不存在。它现在似乎是一个replicaSet。

./cluster/kubectl.sh get rs
NAME                  DESIRED   CURRENT   AGE
my-nginx-2494149703   3         3         9h

我尝试更改副本集中描述的副本数量:

./cluster/kubectl.sh scale --replicas=5 rs/my-nginx-2494149703
replicaset "my-nginx-2494149703" scaled

但我仍然看到我原来的三个豆荚

./cluster/kubectl.sh get pods
NAME                        READY     STATUS    RESTARTS   AGE
my-nginx-2494149703-04xrd   1/1       Running   0          9h
my-nginx-2494149703-h3krk   1/1       Running   0          9h
my-nginx-2494149703-hnayu   1/1       Running   0          9h

我希望看到5个豆荚。

./cluster/kubectl.sh describe rs/my-nginx-2494149703
Name:       my-nginx-2494149703
Namespace:  default
Image(s):   nginx
Selector:   pod-template-hash=2494149703,run=my-nginx
Labels:     pod-template-hash=2494149703
        run=my-nginx
Replicas:   3 current / 3 desired
Pods Status:    3 Running / 0 Waiting / 0 Succeeded / 0 Failed

为什么它不能扩展?我是否还必须更改部署中的某些内容?
当我描述扩展后的rs时,我看到了这样的情况:(这里我试着从一个运行的pod扩展到3个运行的pod)。但它仍然是一个运行的pod。其他2个启动并立即杀死

34s       34s     1   {replicaset-controller }            Normal      SuccessfulCreate    Created pod: my-nginx-1908062973-lylsz
  34s       34s     1   {replicaset-controller }            Normal      SuccessfulCreate    Created pod: my-nginx-1908062973-5rv8u
  34s       34s     1   {replicaset-controller }            Normal      SuccessfulDelete    Deleted pod: my-nginx-1908062973-lylsz
  34s       34s     1   {replicaset-controller }            Normal      SuccessfulDelete    Deleted pod: my-nginx-1908062973-5rv8u
mm9b1k5b

mm9b1k5b1#

这对我有用

kubectl scale --replicas=<expected_replica_num> deployment <deployment_label_name> -n <namespace>

范例


# kubectl scale --replicas=3 deployment xyz -n my_namespace
0aydgbwb

0aydgbwb2#

TL;DR:您需要扩展部署,而不是直接扩展副本集。
如果您尝试缩放副本集,则它将(在很短的时间内)有一个新的计数5。但是部署控制器将看到副本集的当前计数是5,并且由于它知道它应该是3,所以它将把它重置回3。通过手动修改为您创建的副本集,你是在和系统控制器战斗(它是不知疲倦的,而且几乎总是比你更持久)。

rkttyhzu

rkttyhzu3#

kubectl run中的kubectl run my-nginx --image=nginx --replicas=3 --port=80将创建一个部署作业来管理创建的容器。

部署--〉副本集--〉Pod这是Kubernetes的工作方式。

如果您更改了 * 底层 * 对象,其 * 高层 * 对象将撤消您的更改。您必须更改 * 顶层 * 对象。

tmb3ates

tmb3ates4#

将其按比例缩小到零,然后再按比例缩小到所需的pod数量(猜测它等于3)

kubectl scale deployment <deployment-name> --replicas=0 -n <namespace>
kubectl scale deployment <deployment-name> --replicas=3 -n <namespace>
laawzig2

laawzig25#

我不确定这是否是最好的方法,因为我是从kubernetes开始的,但是我通过更新我的yaml文件做到了这一点


# app.yaml

apiVersion: apps/v1
...
spec:
  replicas: <new value>

并运行$ kubectl scale -f app.yaml --replicas=<new value>
您可以通过运行$ kubectl get pods来验证新的副本数量
在我的例子中,我也对缩减我的虚拟机感兴趣,在谷歌云。

z3yyvxxp

z3yyvxxp6#

下面的示例显示了您应该如何扩大/缩小您的“pod/resource/deployments”。

k8smaster@k8smaster:~/debashish$ more createdeb_deployment1.yaml 

--- 
apiVersion: apps/v1beta2
kind: Deployment
metadata: 
  name: debdeploy-webserver
spec: 
  replicas: 1
  selector: 
    matchLabels: 
      app: debdeploy1webserver
  template: 
    metadata: 
      labels: 
        app: debdeploy1webserver
    spec: 
      containers: 
        - 
          image: "docker.io/debu3645/debapachewebserver:v1"
          name: deb-deploy1-container 
          ports: 
            - 
              containerPort: 6060

已创建部署--〉


**kubectl -n debns1 create -f createdeb_deployment1.yaml**

k8smaster@k8smaster:~/debashish$ `kubectl scale --replicas=5**deployment**/debdeploy-webserver -n debns1`

(纵向扩展5个部署)

k8smaster@k8smaster:~/debashish$ kubectl get pods -n debns1

NAME                                   READY   STATUS    RESTARTS   AGE
debdeploy-webserver-7cf4fb74c5-8wvzx   1/1     Running   0          16s
debdeploy-webserver-7cf4fb74c5-jrf6v   1/1     Running   0          16s
debdeploy-webserver-7cf4fb74c5-m9fpw   1/1     Running   0          16s
debdeploy-webserver-7cf4fb74c5-q9n7r   1/1     Running   0          16s
debdeploy-webserver-7cf4fb74c5-ttw6p   1/1     Running   1          19h
resourcepod-deb1                       1/1     Running   5          6d18h

k8smaster@k8smaster:~/debashish$**kubectl get ep -n debns1**

NAME                ENDPOINTS                                                     AGE
frontend-svc-deb    192.168.1.10:80,192.168.1.11:80,192.168.1.12:80 + 2 more...   18h
frontend-svc1-deb   192.168.1.8:80                                                14d
frontend-svc2-deb   192.168.1.8:80                                                5d19h

k8smaster@k8smaster:~/debashish$**kubectl scale --replicas=2**deployment/debdeploy-webserver -n debns1

从5个缩减到2个
扩展名/debeploy-webserver已扩展

k8smaster@k8smaster:~/debashish$**kubectl get pods -n debns1**

NAME                                   READY   STATUS        RESTARTS   AGE
debdeploy-webserver-7cf4fb74c5-8wvzx   1/1     Terminating   0          35m
debdeploy-webserver-7cf4fb74c5-jrf6v   1/1     Terminating   0          35m
debdeploy-webserver-7cf4fb74c5-m9fpw   1/1     Terminating   0          35m
debdeploy-webserver-7cf4fb74c5-q9n7r   1/1     Running       0          35m
debdeploy-webserver-7cf4fb74c5-ttw6p   1/1     Running       1          19h
resourcepod-deb1                       1/1     Running       5          6d19h

k8smaster@k8smaster:~/debashish$**kubectl get pods -n debns1**

NAME                                   READY   STATUS    RESTARTS   AGE
debdeploy-webserver-7cf4fb74c5-q9n7r   1/1     Running   0          37m
debdeploy-webserver-7cf4fb74c5-ttw6p   1/1     Running   1          19h
resourcepod-deb1                       1/1     Running   5          6d19h

k8smaster@k8smaster:~/debashish$ kubectl**scale --current-replicas=4 --replicas=2**deployment/debdeploy-webserver -n debns1  (Check the current no. of deployments. If current replication is 4, then bring it down to 2, else dont do anything)

error: Expected replicas to be 4, was 2

k8smaster@k8smaster:~/debashish$**kubectl scale --current-replicas=3 --replicas=10 deployment/debdeploy-webserver -n debns1**

error: Expected replicas to be 3, was 2

k8smaster@k8smaster:~/debashish$**kubectl scale --current-replicas=2 --replicas=10 deployment/debdeploy-webserver -n debns1**

扩展名/debeploy-webserver已扩展

k8smaster@k8smaster:~/debashish$**kubectl get pods -n debns1**

    NAME                                   READY   STATUS              RESTARTS   AGE
    debdeploy-webserver-7cf4fb74c5-46bxg   1/1     Running             0          6s
    debdeploy-webserver-7cf4fb74c5-d6qsx   0/1     ContainerCreating   0          6s
    debdeploy-webserver-7cf4fb74c5-fdq6v   1/1     Running             0          6s
    debdeploy-webserver-7cf4fb74c5-gd87t   1/1     Running             0          6s
    debdeploy-webserver-7cf4fb74c5-kqdbj   0/1     ContainerCreating   0          6s
    debdeploy-webserver-7cf4fb74c5-q9n7r   1/1     Running             0          47m
    debdeploy-webserver-7cf4fb74c5-qjvm6   1/1     Running             0          6s
    debdeploy-webserver-7cf4fb74c5-skxq4   0/1     ContainerCreating   0          6s
    debdeploy-webserver-7cf4fb74c5-ttw6p   1/1     Running             1          19h
    debdeploy-webserver-7cf4fb74c5-wlc7q   0/1     ContainerCreating   0          6s
    resourcepod-deb1                       1/1     Running             5          6d19h
jckbn6z7

jckbn6z77#

用于部署

kubectl scale deployment <deployment-name> --replicas=3 -n <namespace>

用于状态集

kubectl scale statefulsets <stateful-set-name> --replicas=3 -n <namespace>

相关问题