클러스터에서 DNS 서비스 자동 스케일링하기
클러스터에서 DNS 서비스 자동 스케일링하기 (Autoscale the DNS Service in a Cluster)
이 페이지는 쿠버네티스 클러스터에서 DNS 서비스의 자동 스케일링을 활성화하고 구성하는 방법을 보여줘요.
출처: 문서
본문
시작하기 전에 (Before you begin)
DNS 수평 자동 스케일링이 이미 활성화되어 있는지 확인하기
kube-system 네임스페이스에서 클러스터의 Deployments를 나열해요:
kubectl get deployment --namespace=kube-system
출력은 다음과 비슷해요:
NAME READY UP-TO-DATE AVAILABLE AGE
...
kube-dns-autoscaler 1/1 1 1 ...
...
출력에서 "kube-dns-autoscaler"가 보이면 DNS 수평 자동 스케일링이 이미 활성화된 것이고, 자동 스케일링 매개변수 조정으로 건너뛸 수 있어요.
DNS Deployment의 이름 얻기
kube-system 네임스페이스에서 클러스터의 DNS deployment를 나열해요:
kubectl get deployment -l k8s-app=kube-dns --namespace=kube-system
출력은 다음과 비슷해요:
NAME READY UP-TO-DATE AVAILABLE AGE
...
coredns 2/2 2 2 ...
...
DNS 서비스에 대한 Deployment가 보이지 않으면 이름으로도 찾을 수 있어요:
kubectl get deployment --namespace=kube-system
그리고 coredns 라는 이름의 deployment를 찾아봐요.
스케일 대상은
Deployment/<your-deployment-name>
여기서 <your-deployment-name> 은 DNS Deployment의 이름이에요. 예를 들어 DNS용 Deployment 이름이 coredns라면 스케일 대상은 Deployment/coredns예요.
참고:
DNS 수평 자동 스케일링 활성화하기
이 섹션에서 새 Deployment를 만들어요. Deployment의 파드는 cluster-proportional-autoscaler-amd64 이미지 기반 컨테이너를 실행해요.
dns-horizontal-autoscaler.yaml 이라는 파일을 이 내용으로 만들어요:
kind: ServiceAccount
apiVersion: v1
metadata:
name: kube-dns-autoscaler
namespace: kube-system
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: system:kube-dns-autoscaler
rules:
- apiGroups: [""]
resources: ["nodes"]
verbs: ["list", "watch"]
- apiGroups: [""]
resources: ["replicationcontrollers/scale"]
verbs: ["get", "update"]
- apiGroups: ["apps"]
resources: ["deployments/scale", "replicasets/scale"]
verbs: ["get", "update"]
# Remove the configmaps rule once below issue is fixed:
# kubernetes-incubator/cluster-proportional-autoscaler#16
- apiGroups: [""]
resources: ["configmaps"]
verbs: ["get", "create"]
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: system:kube-dns-autoscaler
subjects:
- kind: ServiceAccount
name: kube-dns-autoscaler
namespace: kube-system
roleRef:
kind: ClusterRole
name: system:kube-dns-autoscaler
apiGroup: rbac.authorization.k8s.io
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: kube-dns-autoscaler
namespace: kube-system
labels:
k8s-app: kube-dns-autoscaler
kubernetes.io/cluster-service: "true"
spec:
selector:
matchLabels:
k8s-app: kube-dns-autoscaler
template:
metadata:
labels:
k8s-app: kube-dns-autoscaler
spec:
priorityClassName: system-cluster-critical
securityContext:
seccompProfile:
type: RuntimeDefault
supplementalGroups: [ 65534 ]
fsGroup: 65534
nodeSelector:
kubernetes.io/os: linux
containers:
- name: autoscaler
image: registry.k8s.io/cpa/cluster-proportional-autoscaler:1.8.4
resources:
requests:
cpu: "20m"
memory: "10Mi"
command:
- /cluster-proportional-autoscaler
- --namespace=kube-system
- --configmap=kube-dns-autoscaler
# Should keep target in sync with cluster/addons/dns/coredns/coredns.yaml.base
- --target=<SCALE_TARGET>
# When cluster is using large nodes(with more cores), "coresPerReplica" should dominate.
# If using small nodes, "nodesPerReplica" should dominate.
- --default-params={"linear":{"coresPerReplica":256,"nodesPerReplica":16,"preventSinglePointFailure":true,"includeUnschedulableNodes":true}}
- --logtostderr=true
- --v=2
tolerations:
- key: "CriticalAddonsOnly"
operator: "Exists"
serviceAccountName: kube-dns-autoscaler
파일에서 <SCALE_TARGET> 을 스케일 대상으로 바꿔요.
구성 파일이 있는 디렉토리로 이동해 이 명령을 입력해 Deployment를 만들어요:
kubectl apply -f dns-horizontal-autoscaler.yaml
성공한 명령의 출력은 다음과 같아요:
deployment.apps/kube-dns-autoscaler created
이제 DNS 수평 자동 스케일링이 활성화됐어요.
DNS 자동 스케일링 매개변수 조정하기
kube-dns-autoscaler ConfigMap이 존재하는지 확인해요:
kubectl get configmap --namespace=kube-system
출력은 다음과 비슷해요:
NAME DATA AGE
...
kube-dns-autoscaler 1 ...
...
ConfigMap의 데이터를 수정해요:
kubectl edit configmap kube-dns-autoscaler --namespace=kube-system
이 줄을 찾아요:
linear: '{"coresPerReplica":256,"min":1,"nodesPerReplica":16}'
필드를 필요에 따라 수정해요. "min" 필드는 DNS 백엔드의 최소 수를 나타내요. 실제 백엔드 수는 다음 방정식으로 계산돼요:
replicas = max( ceil( cores × 1/coresPerReplica ) , ceil( nodes × 1/nodesPerReplica ) )
coresPerReplica 와 nodesPerReplica 값이 모두 float라는 점을 기억해요.
아이디어는 클러스터가 코어가 많은 노드를 사용할 때 coresPerReplica 가 지배하고, 코어가 적은 노드를 사용할 때 nodesPerReplica 가 지배한다는 것이에요.
다른 지원되는 스케일링 패턴도 있어요. 자세한 내용은 cluster-proportional-autoscaler를 참고해요.
DNS 수평 자동 스케일링 비활성화하기
DNS 수평 자동 스케일링을 조정하는 몇 가지 옵션이 있어요. 어떤 옵션을 사용할지는 서로 다른 조건에 따라 달라져요.
옵션 1: kube-dns-autoscaler deployment를 0 레플리카로 축소하기
이 옵션은 모든 상황에서 동작해요. 다음 명령을 입력해요:
kubectl scale deployment --replicas=0 kube-dns-autoscaler --namespace=kube-system
출력은:
deployment.apps/kube-dns-autoscaler scaled
레플리카 수가 0인지 확인해요:
kubectl get rs --namespace=kube-system
출력은 DESIRED와 CURRENT 열에 0을 표시해요:
NAME DESIRED CURRENT READY AGE
...
kube-dns-autoscaler-6b59789fc8 0 0 0 ...
...
옵션 2: kube-dns-autoscaler deployment 삭제하기
이 옵션은 kube-dns-autoscaler가 자신의 통제 하에 있을 때(즉 아무도 다시 만들지 않을 때) 동작해요:
kubectl delete deployment kube-dns-autoscaler --namespace=kube-system
출력은:
deployment.apps "kube-dns-autoscaler" deleted
옵션 3: 마스터 노드에서 kube-dns-autoscaler 매니페스트 파일 삭제하기
이 옵션은 kube-dns-autoscaler가 (더 이상 사용되지 않는) Addon Manager의 통제 하에 있고 마스터 노드에 쓰기 접근이 있을 때 동작해요.
마스터 노드에 로그인해 해당 매니페스트 파일을 삭제해요. 이 kube-dns-autoscaler의 일반적인 경로는:
/etc/kubernetes/addons/dns-horizontal-autoscaler/dns-horizontal-autoscaler.yaml
매니페스트 파일이 삭제된 후 Addon Manager가 kube-dns-autoscaler Deployment를 삭제해요.
DNS 수평 자동 스케일링이 동작하는 방식 이해하기
더 알아보기 (Learn more)
- 중요 애드온 파드의 보장된 스케줄링 읽기
- cluster-proportional-autoscaler의 구현에 대해 더 알아보기