• 검색 결과가 없습니다.

쿠버네티스 Best Practices 또는 Lessons learned, 그리고 GKE(Google Kubernetes Engine)

N/A
N/A
Protected

Academic year: 2022

Share "쿠버네티스 Best Practices 또는 Lessons learned, 그리고 GKE(Google Kubernetes Engine)"

Copied!
51
0
0

로드 중.... (전체 텍스트 보기)

전체 글

(1)

쿠버네티스 Best Practices 또는 Lessons learned, 그리고

GKE(Google Kubernetes Engine)

Google Cloud Customer Engineer 이정운 (jungwoon@google.com)

2020.11

(2)

Kubernetes 는 컨테이너를 위한 오케스트레이션 도구로서

애플리케이션 내에서 어떻게

컨테이너들을 함께 동작하는지 제어

Open source

Runs on almost any infrastructure, public or private

Supported by a broad ecosystem of partners, offering you cloud provider flexibility

Powered by

Kubernetes.

(3)

3

Kubernetes - Container Orchestration

● 컨테이너화 된 애플리케이션의 배치, 확장 및 관리를 자동화하는 오픈 소스

(4)

4

Google

Kubernetes Engine

(5)

5

Kubernetes 를

사용하는 가장 쉬운 방법

한 번의 클릭으로 클러스터를 시작

단일 창에서 클러스터 및 워크로드를 모니터

Google 은 클러스터를 계속 동작 유지

(6)

Google Kubernetes Engine(GKE)

GKE 는 Google Cloud’s Kubernetes Platform

Generally Available in August 2015

Google Cloud Platform 기능 및 서비스와의 긴밀한 통합 및 이점 활용

Kubernetes Master, Fully Managed by Google

Nodes Nodes Node Pool C Node Pool B

Node Pool A

Nodes with Automated Operations via GKE

GKE Cluster

(7)

7

15+ years experience in application orchestration

July 15 K8s 1.0

Jun 14 First Github commit for Kube Public Beta of

Solaris Containers

Birth of Borg, 3-4 Google Engineers working to automate cluster management.

2018

2009 2012 2015

Work begins to opensource Google’s Borg as Kubernetes

Process Containers launched by Google now known as cgroups and merged with Linux Kernel.

LXC launched, complete Linux container manager

2013 Docker launched

GKE on Prem Announced

Gvisor Knative

Istio 1.0

Istio 0.1 Envoy 1.0 Aug 15

GKE GA

Nov 14 GKE Alpha

2019

Anthos

2003 2006 2009 2012 2015 2018 2019

(8)

Google Kubernetes Engine(GKE)

안정성

더욱 강화된 보안으로 신뢰할 수 있는 네트워킹과 강력한

가용성으로 Kubernetes를 관리하고 운영하는 안전한 방법

효율성

원활한 운영, 워크로드 이동성, 절감된 비용으로 Kubernetes의 운영 오버헤드 감소

성능

활발한 통합 생태계에서 Kubernetes의 성능을 꾸준히 유지하여 개발자 생산성 향상

(9)

Marquee customers

Kubernetes Engine (GKE) 사례

(10)

3D multiplayer battle game.

Publisher: Colopl

Title: Bakuretsu Monster Platform: Android & iOS

GCP products used:

Google Kubernetes Engine

Cloud Spanner

● Cloud Storage

● Cloud Load Balancing

● Stackdriver

● BigQuery

멀티 플레이 전투 게임

(11)

멀티 플레이 전투 게임 - 아키텍처

Before After

(12)

Burmuda

많은 영역에 Firebase 사용중

- 직원이 9명인 스타트 업 회사로 Firebase 를 통해 인프라 운영 감소

서비스 사용 고객이 많아지면서 일부 GKE 변환

- 일부 GKE 로 전환하면서 비용 효율성 개선 (약 80%) (자동 확장과 세밀한 리소스 조정)

- 확장성 (평소 노드 4 → 노드 33 개 로 접속자에 따라 자동 조절)

- 편리한 모니터링을 통해 리소스 관리

- 클라우드 관리에 대한 노력을 줄이고, 개발에 집중하고 있음

신규 추가되는 기능들은 모두 GKE로 개발하고, 기존 서비스 일부도 옮길 계획

https://cloud.google.com/customers/bermuda/?hl=ko

(13)

쿠버네티스 Best Practices 또는 Lessons learned,

그리고 GKE

(14)

14

1. Born on the basis of Borg

(15)

15

Borg at a glance

Manages container clusters in Google data centers

“A datacenter is not a collection of computers, a datacenter is a computer” – Urs Hölzle, et al.

Even Compute Engine VMs run in containers on Borg, enabling technology like Live

Migration

web browsers

BorgMaster

link shard UI shard BorgMaster

link shard UI shard BorgMaster

link shard UI shard BorgMaster

link shard UI shard Cell

borgcfg web browsers

scheduler

Borglet Borglet Borglet Borglet

BorgMaster

link shard read/UI

shard Config

file

persistent store (Paxos) Binary

Scheduler

1. Born on the basis of Borg

(16)

16

1. Born on the basis of Borg

(17)

17

Use labels

App: MyApp Phase: prod Role: FE

App: MyApp Phase: test Role: FE

App: MyApp Phase: prod Role: BE

App: MyApp Phase: test Role: BE

Define and use labels that identify semantic attributes of your

application or Deployment, such as:

App: MyApp

Phase: Prod

You can use these labels to select the appropriate Deployments for other resources such as

ReplicaSets and Services.

1. Born on the basis of Borg

(18)

18

1. Born on the basis of Borg

2. A lot of attention and a lot of attack.

(19)

19

2. A lot of attention and a lot of attack.

(20)

20

2. A lot of attention and a lot of attack.

Auto Kubernetes

Auto-repair

상태 확인에 실패한 노드에 대한 복구 프로세스를 자동으로 시작

Auto-upgrade 안정적인 최신 버전으로

클러스터의 control plane 및 노드를 최신 상태로 유지

Auto-scale

클러스터 자동 확장으로 증가 된 수요를 처리하고 필요에 따라 자동 확장

For Master Node

For Worker Nodes

GKE 제공 이점

(21)

21

2. A lot of attention and a lot of attack.

Auto Kubernetes

Auto-repair

상태 확인에 실패한 노드에 대한 복구 프로세스를 자동으로 시작

Auto-upgrade 안정적인 최신 버전으로

클러스터의 control plane 및 노드를 최신 상태로 유지

Auto-scale

클러스터 자동 확장으로 증가 된 수요를 처리하고 필요에 따라 자동 확장

참고 : https://cloud.google.com/kubernetes-engine/docs/concepts/release-channels

GKE 제공 이점

(22)

22

1. Born on the basis of Borg

2. A lot of attention and a lot of attack.

3. Need to consider VM as well

(23)

23

3. Need to consider VM as well

GCE 의 기술적 이점 상속

● Custom type 지원(필요한 코어, 메모리 지정 가능)

● 다양한 타입 지원 (N1, N2, N2D, C2, E2, M2 등)

● Preemptible VM 활용 가능 - 최대 80% 저렴

참고 : https://cloud.google.com/compute/docs/machine-types#recommendations_for_machine_types

● 비용 최적화 타입 : E2 - N1 대비 약 30% 저렴

● 성능 최적화 타입 : C2 - 최신 Intel Cascade lake 칩 기반으로 최대 3.8 Ghz All-cores turbo 제공

● AMD EPYC 기반 : N2D

(24)

24

1. Born on the basis of Borg

2. A lot of attention and a lot of attack.

3. Need to consider VM as well 4. Container image

(25)

25

4. Container image

Don’t use :latest or no tag, Change tag every new container build Be consider to use Base image

Make image light - understand layer and caching

참고 : https://bcho.tistory.com/1356,

https://bcho.tistory.com/1357?category=731548

(26)

26

4. Container image

Container-Optimized OS 제공

● Google Cloud Platform에 맞춰 설계된 컨테이너용 OS

● Google에서 설계 및 유지 관리하며 GCP와 완벽하게 통합

Ubuntu 도 지원

GKE 제공 이점

참고 : https://cloud.google.com/container-optimized-os

(27)

27

4. Container image

containerd 지원 가능

● docker 가 아닌 containerd 사용 가능(컨테이너 표준 인 OCI (Open Container Initiative)를 준수)

GKE 제공 이점

참고:https://kubernetes.io/blog/2018/05/24/kubernetes-containerd-integration-goes-ga/

http://www.opennaru.com/kubernetes/containerd/?fbclid=IwAR1bkTv5sIiTcq1aXHE1C-N7aaULgZL8WjxigFrsAvThCCZAoFEqfcmGyZI

(28)

28

1. Born on the basis of Borg

2. A lot of attention and a lot of attack.

3. Need to consider VM as well 4. Container image

5. Container Runtime

(29)

29

5. Container Runtime

Consider scheduling - Taints & Tolerations, Affinity & Anti-affinity

참고 :

https://cloud.google.com/blog/products/gcp/kubernetes-best-practices-setting-up-health-checks-with-readiness-and-liveness-probes

Use readiness and liveness probes for health checks

- Readniss : Readiness probes are designed to let Kubernetes know when your app is ready to serve traffic - Liveness : Liveness probes let Kubernetes know if your app is alive or dead

(30)

30

5. Container Runtime

Requests : requested amount of resource for a container

Limits : limit of resource that can be consumed by a container

Requests and limits are on a per-container basis. (Not a pod)

Consider LimitRange to define the default size for a container deployed in the specific namespace.

Container

requests limits

apiVersion: v1 kind: Pod metadata:

name: frontend spec:

containers:

- name: db image: mysql resources:

requests:

memory: "64Mi"

cpu: "250m"

limits:

memory: "128Mi"

cpu: "500m"

Consider requests & limits + LimitRange

(31)

31

5. Container Runtime

Terminating with grace

1. Pod is set to the “Terminating” State and

removed from the endpoints list of all Services 2. preStop Hook is executed

3. SIGTERM signal is sent to the pod 4. Kubernetes waits for a grace period

5. SIGKILL signal is sent to pod, and the pod is removed

참고: https://cloud.google.com/blog/products/gcp/kubernetes-best-practices-terminating-with-grace

(32)

32

5. Container Runtime

수평으로 인프라 확장 Cluster Autoscaling

Trigger: Pending Pods that Need Resources

수평으로 워크로드 확장 Horizontal Pod Autoscaling

Triggers: CPU or Custom Metrics

Nodes Nodes Nodes Nodes

Nodes

Nodes Nodes Nodes Nodes

GKE 제공 이점 - 설정을 통한 확장 가능

수직으로 인프라 확장 Node Auto Provisioning

Trigger: Resources Required by Pods Larger than Existing Node Pools

수직으로 워크로드 확장 Vertical Pod Autoscaling

Triggers: VPA Recommendations

Nodes Nodes

참고: https://cloud.google.com/solutions/best-practices-for-running-cost-effective-kubernetes-applications-on-gke

(33)

33

1. Born on the basis of Borg

2. A lot of attention and a lot of attack.

3. Need to consider VM as well 4. Container image

5. Container Runtime 6. Network

(34)

34

6. Network

Understand basic network concepts of Kubernetes

Consider CIDR range according to the size of k8s cluster

참고 : https://cloud.google.com/kubernetes-engine/docs/how-to/flexible-pod-cidr

https://medium.com/google-cloud/kubernetes-nodeport-vs-loadbalancer-vs-ingress-when-should-i-use-what-922f010849e0

(35)

35

6. Network

GKE 의 네트워크 이점 #1

K8s 는 private IP 가 분리되어 외부 VM 과 커뮤니케이션을 위해서는 NAT 필요

GKE 는 K8s 와 VM 이 같은 VPC 공유 가능 (Alias IP)

Kubernetes Cluster VM

NAT

Private network Private network

Kubernetes

Kubernetes Cluster VM

Private network

GKE

참고: https://cloud.google.com/kubernetes-engine/docs/how-to/container-native-load-balancing

GKE 의 네트워크 이점 #2

GKE 는 k8s 와 다르게 Network endpoint groups (NEGs) 를 통해서 요청을 처리하는 컨테이너에 직접로드 밸런싱 가능

NEG 의 경우 iptables 에 의한 트래픽 Node 이동을 방지

(36)

36

6. Network

GKE 의 네트워크 이점 #3

GKE Dataplane V2(beta)

Extended Berkeley Packet Filter (eBPF) : Linux 커널 내부의 네트워크 스택에 프로그래밍 가능한 hook 을 노출하는 새로운 Linux 네트워킹 패러다임

eBPF는 커널을 다시 컴파일하거나 커널 모듈을 로드하지 않고도 Linux 커널에서 샌드 박스 프로그램을 실행할 수있는 혁신적인 기술

Cilium : eBPF를 사용하는 Linux 커널을

Kubernetes 가 인식할 수 있도록 지원하는 오픈 소스 프로젝트

GKE Dataplane V2는 정책 로깅에 필요한 정보를 노출 할 뿐만 아니라 사용자의 네트워크 정책 시행 구성 세부 정보를 완전히 추상화

네트워크 정책 외에도 Kubernetes 부하 분산은 eBPF를 사용하여 DSR (Direct Server Return) 모드를 구현 가능

참고: https://cloud.google.com/blog/products/containers-kubernetes/bringing-ebpf-and-cilium-to-google-kubernetes-engine

(37)

37

1. Born on the basis of Borg

2. A lot of attention and a lot of attack.

3. Need to consider VM as well 4. Container image

5. Container Runtime 6. Network

7. Monitoring & Logging

(38)

38

7. Monitoring & Logging

Use container native logging: stdout and stderr

Monitor and log as much as possible

(39)

39

7. Monitoring & Logging

GKE 제공 이점

Kubernetes Engine을 지원하는 다중 클러스터 모니터링 - GCP 및 Kubernetes 환경을 단일 모니터링

Kubernetes 에서 자주 사용되는 모니터링 도구인 Prometheus 연동 구성 가능

Datadog 과 같은 3rd-party 모니터링 도구와 손쉬운 연동 가능

(40)

40

1. Born on the basis of Borg

2. A lot of attention and a lot of attack.

3. Need to consider VM as well 4. Container image

5. Container Runtime 6. Network

7. Monitoring & Logging 8. Security

(41)

41

8. Security

Configure Security Context

Avoid running as root

Good

FROM node:carbon EXPOSE 8080

RUN groupadd -r -g 2001 appuser && useradd -r -u 1001 -g appuser appuser RUN mkdir /home/appuser && chown appuser /home/appuser

USER appuser

WORKDIR /home/appuser

COPY --chown=appuser:appuser server.js . CMD node server.js > /home/appuser/log.out

Bad

FROM node:carbon EXPOSE 8080

WORKDIR /home/appuser COPY server.js .

CMD node server.js > /home/appuser/log.out

(42)

42

8. Security

GKE 이점 - GKE Sandbox

● GKE Sandbox 는 오픈 소스인 gVisor 기반

● gVisor는 각 컨테이너에 독립적인 운영 체제 커널을 제공하여 작동

● 응용 프로그램은 호스트 커널이 아닌 gVisor 커널이 제공하는 가상화 된 환경과 상호 작용

GKE 이점 - GCR : 취약점 검사 및 보고

● 알려진 CVE (Common Vulnerabilities and Exposures)에 대해 Google Container Registry 의 이미지를 스캔

이미지가 추가되거나 vulnerability database 가 업데이트 되었을 때 수행

(43)

43

8. Security

Trusted

Virtual Private Cloud (VPC) Kubernetes Engine Cluster

Node Node Node

Google Kubernetes Engine Kubernetes Master

Trusted On-prem

Host Host VPN

Untrusted Internet

GKE 제공 이점 - Private Clusters

(44)

44

1. Born on the basis of Borg

2. A lot of attention and a lot of attack.

3. Need to consider VM as well 4. Container image

5. Container Runtime 6. Network

7. Monitoring & Logging 8. Security

9. It’s running on GCP with GCP Ecosystem

(45)

45

9. It’s running on GCP with GCP Ecosystem It can utilize full advantages of GCP

(46)

46

9. It’s running on GCP with GCP Ecosystem

GKE 제공 이점 - Load Balancer

Services L4 네트워크 부하 분산을 제공

GCLB 컨트롤러를 사용하면 Ingress 내부 LB의 L7 HTTP/S로드 밸런서를 제공하여 동일한 네트워크의 클러스터 외부의 응용 프로그램에서 k8s 서비스가 활성화

Kubemci 를 사용하면 멀티 클러스터의 Ingress를 구성 할 수 있습니다

(47)

47

9. It’s running on GCP with GCP Ecosystem

GKE 제공 이점 - Cloud Build

GitHub, Bitbucket, Cloud Source Repository 와 연결 가능

Cloud Build 의 Build Trigger 를 통해 코드 변경 사항 발생 시 자동 빌드 구성

참고 : https://cloud.google.com/kubernetes-engine/docs/tutorials/gitops-cloud-build

(48)

48

9. It’s running on GCP with GCP Ecosystem

GKE 제공 이점 - Config Connector

참고 : https://cloud.google.com/config-connector/docs/overview

Config Connector

Config Connector Kubernetes를 통해 Google Cloud 리소스를 관리할 수 있는 Kubernetes 부가기능

(49)

49

9. It’s running on GCP with GCP Ecosystem

GKE 제공 이점 - Workload Identity

Workload Identity

GKE 애플리케이션이 다른 Google Cloud 서비스를 인증하고

사용하는 새로운 방식 향상된 보안 속성과 관리 용이성으로 인해 GKE 내에서 Google Cloud 서비스에 액세스하는 데 권장되는 방법

참고 : https://cloud.google.com/kubernetes-engine/docs/how-to/workload-identity#using-gcloud-init https://medium.com/@mohanpedala/enable-workload-identity-on-gke-cluster-9ff139baa2ea

(50)

50

Automation Security

Openness

GKE for Enterprises

based on Kubernetes Best Practices

(51)

51

The End of Document.

참조

관련 문서

전자정부 클라우드 플랫폼과 개방형 클라우드 플랫폼(PaaS-TA)에 채택되어 있는 Container Orchestration 는 Kubernetes 와 Cloud Foundry 의 Diego 이며, Service

- 웹사이트 소유자를 위한 서비스: 개인 홈페이지나 블로그에 관련성이 높은 배너 광고를

1) Start/stop the pump with the START/STOP buttons on the front panel or START/STOP signal connected to the remote connector or SERIAL COMMUNICATION connector on the rear

Step1) Select your type in Engine Type menu and then start the engine with the preset configuration values maintaining it with no load. Step2) During

parallel processing (e.g. ETL) of large data sets in Google Cloud Supports both Streaming and Batch processing (no need for separate pipeline code development). Autoscales

SigmaNEST 펀칭 파워팩 제품 관리, 자동 다이나믹™ 배 열 및 펀칭 툴 관리를 갖춘 터렛 펀칭 프로그래밍을 위한 가장 완벽하고 최적화된

For safety, when constructing a connection system between a Sensor and panel with a connector, make sure that the connector plug is on the Sensor side and the connector socket

Kubernetes 클러스터 노드가 실패하면 PKS 가 노드를 다시 빌드하고 클러스터를 재구성하며 Kubernetes Control Plane 은 작업 노드에서 포드를 다시 예약. 포트가