Kubernetes之更改副本数
LiuSw Lv6

Kubernetes之更改副本数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
kubectl scale 参数说明

Examples:
# Scale a replicaset named 'foo' to 3.
kubectl scale --replicas=3 rs/foo

# Scale a resource identified by type and name specified in "foo.yaml" to 3.
kubectl scale --replicas=3 -f foo.yaml

# If the deployment named mysql's current size is 2, scale mysql to 3.
kubectl scale --current-replicas=2 --replicas=3 deployment/mysql

# Scale multiple replication controllers.
kubectl scale --replicas=5 rc/foo rc/bar rc/baz

# Scale statefulset named 'web' to 3.
kubectl scale --replicas=3 statefulset/web

Options:
--all=false: Select all resources in the namespace of the specified resource types
--allow-missing-template-keys=true: If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats.
--current-replicas=-1: Precondition for current size. Requires that the current size of the resource match this value in order to scale.
-f, --filename=[]: Filename, directory, or URL to files identifying the resource to set a new size
-k, --kustomize='': Process the kustomization directory. This flag can't be used together with -f or -R.
-o, --output='': Output format. One of: json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-file.
--record=false: Record current kubectl command in the resource annotation. If set to false, do not record the command. If set to true, record the command. If not set, default to updating the existing annotation value only if one already exists.
-R, --recursive=false: Process the directory used in -f, --filename recursively. Useful when you want to manage related manifests organized within the same directory.
--replicas=0: The new desired number of replicas. Required.
--resource-version='': Precondition for resource version. Requires that the current resource version match this value in order to scale.
-l, --selector='': Selector (label query) to filter on, supports '=', '==', and '!='.(e.g. -l key1=value1,key2=value2)
--template='': Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview].
--timeout=0s: The length of time to wait before giving up on a scale operation, zero means don't wait. Any other values should contain a corresponding time unit (e.g. 1s, 2m, 3h).

Usage:
kubectl scale [--resource-version=version] [--current-replicas=count] --replicas=COUNT (-f FILENAME | TYPE NAME) [options]

Use "kubectl options" for a list of global command-line options (applies to all commands).

1
2
3
kubectl scale sts与kubectl scale deploy 
deploy 为无状态的集群
sts 为有状态的集群,像redis,kafka等
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
kubectl -n kubesphere-system scale sts redis-ha-server --replicas=0
kubectl -n kubesphere-system scale deploy redis-ha-haproxy --replicas=0


kubectl -n kubesphere-system scale sts redis-ha-server --replicas=3
kubectl -n kubesphere-system scale deploy redis-ha-haproxy --replicas=3

#集群状态
kubectl -n kubesphere-system exec -it redis-ha-server-1 redis-cli info replication

#redis正常后
kubectl -n kubesphere-system scale deploy ks-apigateway --replicas=0
kubectl -n kubesphere-system scale deploy ks-apigateway --replicas=1

kubectl -n kubesphere-system rollout restart deploy ks-account

kubectl -n kubesphere-system scale deploy ks-apigateway --replicas=3
kubectl -n kubesphere-system scale deploy ks-apigateway --replicas=3
 评论