Ce diaporama a bien été signalé.
Le téléchargement de votre SlideShare est en cours. ×

Kubernetes on Premise Practical Guide

Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Prochain SlideShare
Prometheus in openstack-helm
Prometheus in openstack-helm
Chargement dans…3
×

Consultez-les par la suite

1 sur 64 Publicité

Kubernetes on Premise Practical Guide

Télécharger pour lire hors ligne

Presentation for DevOps Korea Meetup 2019
(http://meetup.devopskorea.com/201906)

Practical Guide about setup Kubernetes cluster on Premise.
- Multi Master Node, etcd
- MetalLB
- Rook with Ceph
- Monitoring (Prometheus, Elasticsearch, NexClipper)
- Managing ServiceAccount

Presentation for DevOps Korea Meetup 2019
(http://meetup.devopskorea.com/201906)

Practical Guide about setup Kubernetes cluster on Premise.
- Multi Master Node, etcd
- MetalLB
- Rook with Ceph
- Monitoring (Prometheus, Elasticsearch, NexClipper)
- Managing ServiceAccount

Publicité
Publicité

Plus De Contenu Connexe

Diaporamas pour vous (20)

Similaire à Kubernetes on Premise Practical Guide (20)

Publicité

Plus récents (20)

Publicité

Kubernetes on Premise Practical Guide

  1. 1. Kubernetes on Premise Practical Guide
  2. 2. Kubernetes로 인프라를 옮기며 경험한 내용을 바탕으로 정리한, 클러스터 구축 실용 가이드를 공유합니다
  3. 3. Setup Kubernetes Cluster
  4. 4. Multi Master Nodes (1) ● kubeadm 명령을 이용해 Multi Master Nodes 클러스터 구축 가능 ● 노드 여유가 있다면 클러스터를 생성할 때 Multi Master 구성 적용 ● Kubernetes 1.14.x 이상 ○ --experimental-upload-certs 옵션을 이용해 인증서 공유 ● Kubernetes 1.13.x 이하 ○ Master Node 생성 후에 인증서를 다른 Master 노드로 복사하는 작업 필요
  5. 5. Multi Master Nodes (2) ● kubeadm-config.yaml ● controlPlaneEndpoint 항목에 내부에서 사용하는 LoadBalancer IP 지정 ○ HAProxy 등을 이용한 LoadBalancer IP ○ Keepalived, Heartbeat 등을 이용한 Failover 구성 적용 가능 apiVersion: kubeadm.k8s.io/v1beta1 kind: ClusterConfiguration kubernetesVersion: 1.14.1 controlPlaneEndpoint: "NODEIP:6443"
  6. 6. Master Node 추가: 1.14.x 이상 ● Master Node 생성 ● Master Node 추가 $ sudo kubeadm init --config kubeadm-config.yaml --experimental-upload-certs $ sudo kubeadm join NODEIP:6443 --token 9vr73a.a8uxyaju799qwdjv --discovery-token-ca-cert-hash sha256:7c2e69131a36ae2a042a339b33381c6d0d43887e2de83720eff5359e26aec866 --experimental-control-plane --certificate-key f8902e114ef118304e561c3ecd4d0b543adc226b7a07f675f56564185ffe0c07
  7. 7. Master Node 추가: 1.13.x 이하 (1) ● Master Node 생성 ● 복사할 인증서 목록 $ sudo kubeadm init --config kubeadm-config.yaml /etc/kubernetes/pki/ca.crt /etc/kubernetes/pki/front-proxy-ca.crt /etc/kubernetes/pki/ca.key /etc/kubernetes/pki/front-proxy-ca.key /etc/kubernetes/pki/sa.key /etc/kubernetes/pki/etcd/ca.crt /etc/kubernetes/pki/sa.pub /etc/kubernetes/pki/etcd/ca.key
  8. 8. Master Node 추가: 1.13.x 이하 (2) ● Master Node 추가 ● 구성 확인 $ sudo kubeadm join NODEIP:6443 --token 9vr73a.a8uxyaju799qwdjv --discovery-token-ca-cert-hash sha256:7c2e69131a36ae2a042a339b33381c6d0d43887e2de83720eff5359e26aec866 --experimental-control-plane $ kubectl get nodes NAME STATUS ROLES AGE VERSION k8s-1 Ready master 3d v1.14.1 k8s-2 Ready master 3d v1.14.1 k8s-3 Ready master 3d v1.14.1
  9. 9. ETCD Cluster (1) ● Etcd 클러스터 구성 ○ External Etcd 구성은 노드 여유가 있고 관리할 여력이 있다면 고려 ○ Etcd 클러스터 최소 가용 노드 수를 유지하는 것이 매우 중요 ○ (n / 2) + 1 노드 수를 유지하지 못할 경우에는 클러스터 운영에 영향 Cluster Size Majority Failure Tolerance 3 2 1 4 3 1 5 3 2 6 4 2
  10. 10. ETCD Cluster (2) ● Etcd client 설치 ● Etcd member list 확인 $ sudo ETCDCTL_API=3 etcdctl --cacert /etc/kubernetes/pki/etcd/ca.crt --cert /etc/kubernetes/pki/etcd/peer.crt --key /etc/kubernetes/pki/etcd/peer.key member list 18b80ec995adf496, started, k8s-3, https://10.10.1.4:2380, https://10.10.1.4:2379 2ee7a00cdb8ac627, started, k8s-1, https://10.10.1.2:2380, https://10.10.1.2:2379 bcd6b446c02976ab, started, k8s-2, https://10.10.1.3:2380, https://10.10.1.3:2379 $ sudo apt install etcd-client
  11. 11. Pod Network Add-on ● Network Add-on IP 대역과 노드에서 사용하는 대역이 겹칠 경우 문제 ○ 예) Weave Net 은 기본값으로 10.32.0.0/12 사용 ○ 노드에서 10.0.0.0/8 대역을 사용할 경우 ○ 10.32.x.y IP 주소에 대한 라우팅을 결정할 수 없음 ● 사용하는 Network Add-on 에 IP 대역을 변경할 수 있는 옵션 이용 ○ 예) 노드에서 10.0.0.0/8 대역 사용 중 ○ Weave Net 이 기본값으로 사용하는 10.32.0.0/12 는 사용 불가 ○ IPALLOC_RANGE 옵션을 이용해 172.30.0.0/16 대역으로 변경
  12. 12. Proxy Mode (1) ● iptables ○ Kubeadm 을 이용해 클러스터를 구축할 경우 기본값 ○ iptables 를 이용해 적절한 성능 보장 ○ 노드가 늘어나고 Pod 증가에 따라 성능 저하 우려 ● ipvs ○ Kubeadm 을 이용해 클러스터를 구축할 때 kubeproxy 옵션을 통해 지정 ○ 대규모 노드에서도 성능 보장 ○ MetalLB 와 동시에 사용할 때 문제 발생 가능성 존재 ■ 적용 전 테스트 필요
  13. 13. Proxy Mode (2) ● ipvsadm 명령을 이용해 제대로 설정되었는지 확인 가능 $ sudo ipvsadm –ln IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP 172.17.0.1:30000 rr -> 172.30.192.6:8443 Masq 1 0 0 TCP 172.17.0.1:31868 rr -> 172.30.192.1:9000 Masq 1 0 0 TCP 172.30.0.1:30000 rr -> 172.30.192.6:8443 Masq 1 0 0 TCP 172.30.0.1:30443 rr -> 172.30.192.8:9000 Masq 1 0 0
  14. 14. Cluster Managements
  15. 15. Management Tools (1) ● Kubernetes Dashboard ○ Web 기반 오픈소스 프로젝트 ○ 사용자 인증 기능 ○ YAML, JSON 파일을 직접 작성해 배포 가능 ○ Deployment, ReplicaSet Scale 조절 가능 ○ 컨테이너 로그 확인 기능 ○ 웹 기반 터미널 기능 제공
  16. 16. Management Tools (2) ● kubectl ○ Command Line Interface 기반 ○ 터미널로 접속하여 빠르게 원하는 작업 수행 가능 ○ Kubectl Plugin 을 통해 추가적인 기능 제공 ● Visual Studio Code: Kubernetes Plugin ○ Kubeconfig 파일을 이용해 로컬 클러스터 관리 가능 ○ YAML 파일 템플릿 제공 ○ TreeView 를 통해 클러스터 내부 컨테이너 상태 확인 가능
  17. 17. Namespace 관리 정책 ● 프로젝트 별로 Namespace 할당 ○ 프로젝트와 관계 있는 모든 자원을 하나의 Namespace 안에서 관리 ○ 구성원이 Namespace 접근 권한을 공유하여 서비스 배포 ○ 예) project-front, project-backend ● 조직 별로 Namespace 할당 ○ 팀에서 사용할 수 있는 자원을 Namespace 별로 나눠 관리 ○ 팀원은 Namespace 안에 있는 자원에 접근 가능 ○ 예) dev-team: default, application, …
  18. 18. Namespace 접근 제어: ServiceAccount ● ServiceAccount 생성 ● Role & RoleBinding 을 이용해 ServiceAccount 접근 권한 제어 ● Namespace 에 접근할 때 사용할 ServiceAccount apiVersion: v1 kind: ServiceAccount metadata: name: ghost-sa namespace: ghost
  19. 19. Namespace 접근 제어: Role kind: Role apiVersion: rbac.authorization.k8s.io/v1beta1 metadata: name: ghost-role namespace: ghost rules: - apiGroups: ["", "extensions", "apps"] resources: ["*"] verbs: ["*"] - apiGroups: ["batch"] resources: - jobs - cronjobs verbs: ["*"]
  20. 20. Namespace 접근 제어: RoleBinding kind: RoleBinding apiVersion: rbac.authorization.k8s.io/v1beta1 metadata: name: ghost-rolebinding namespace: ghost subjects: - kind: ServiceAccount name: ghost-sa namespace: ghost roleRef: apiGroup: rbac.authorization.k8s.io kind: Role name: ghost-role
  21. 21. Cluster Enhancements
  22. 22. MetalLB (1) ● On Premise 환경에서 LoadBalancer 지원 ● Layer 2 Mode or BGP Mode 선택 가능 ● 클러스터 외부에 노출할 IP 대역 지정 필요 ● Proxy Mode 로 ipvs 를 사용할 경우 동작 테스트 필요 ● MetalLB 설치 $ kubectl apply –f https://raw.githubusercontent.com/google/metallb/v0.7.3/manifests/metallb.yaml
  23. 23. MetalLB (2) ● 클러스터 외부에 노출할 IP 대역 설정 apiVersion: v1 kind: ConfigMap metadata: namespace: metallb-system name: config data: config: | address-pools: - name: service-ip-range protocol: layer2 addresses: - 10.10.1.100-10.10.1.250
  24. 24. Rook with Ceph (1) ● Open-Source, Cloud-Native Storage for Kubernetes ○ https://rook.io ● Rook 을 이용해 Ceph 클러스터 생성 및 관리 ● Pod 를 특정 노드에 종속시키지 않고 배포 가능 ● Ceph 클러스터 구축 ○ Bluestore 저장소 설정 ○ 물리 디스크당 OSD ○ 복제본 개수를 2 이상으로 지정하여 데이터 유실 방지
  25. 25. Rook with Ceph (2) ● Ceph 클러스터 구축 ● Dashboard Admin 패스워드 확인 kubectl apply -f cluster/example/kubernetes/ceph/common.yaml kubectl apply -f cluster/example/kubernetes/ceph/operator.yaml kubectl apply -f cluster/example/kubernetes/ceph/cluster.yaml kubectl apply -f cluster/example/kubernetes/ceph/storageclass.yaml kubectl apply -f cluster/example/kubernetes/ceph/filesystem.yaml kubectl apply -f cluster/example/kubernetes/ceph/dashboard-external-http.yaml kubectl apply -f cluster/example/kubernetes/ceph/toolbox.yaml kubectl get secret –n rook-ceph rook-ceph-dashboard-password -o jsonpath="{.data.password}" | base64 -d
  26. 26. CephCluster (1) ● Ceph 클러스터에 사용할 디스크, 데이터 저장 공간 지정 apiVersion: ceph.rook.io/v1 kind: CephCluster metadata: name: rook-ceph namespace: rook-ceph spec: cephVersion: image: ceph/ceph:v14.2.1-20190430 dataDirHostPath: /var/lib/rook dashboard: enabled: true port: 7000 ssl: false
  27. 27. CephCluster (2) storage: config: storeType: "bluestore" databaseSizeMB: "512" journalSizeMB: "512" osdsPerDevice: "1" nodes: - name: "k8s-1" devices: - name: "sdd" - name: "k8s-2" devices: - name: "sdd" - name: "k8s-3" devices: - name: "sdd"
  28. 28. CephBlockPool ● 데이터 유실을 막기 위해 Host 단위로 복제본 유지 apiVersion: ceph.rook.io/v1 kind: CephBlockPool metadata: name: replicapool namespace: rook-ceph spec: replicated: size: 2 failureDomain: host
  29. 29. StorageClass ● PersistentVolumeClaim 에서 사용할 StorageClass 생성 ● rook-ceph-block 을 지정하면, 앞에서 생성한 replicapool 사용 apiVersion: storage.k8s.io/v1 kind: StorageClass metadata: name: rook-ceph-block provisioner: ceph.rook.io/block parameters: blockPool: replicapool clusterNamespace: rook-ceph fstype: xfs
  30. 30. CephFilesystem ● Pod 들이 같이 공유해서 사용하는 Filesystem 저장소 생성 apiVersion: ceph.rook.io/v1 kind: CephFilesystem metadata: name: shared-fs namespace: rook-ceph spec: metadataPool: replicated: size: 2 dataPools: - failureDomain: host replicated: size: 2 metadataServer: activeCount: 1 activeStandby: true
  31. 31. Ceph Dashboard
  32. 32. Ceph Dashboard: Hosts
  33. 33. Ceph Dashboard: Pools
  34. 34. Ceph Tools ● Ceph 클러스터를 관리할 때 필요한 프로그램 모음 $ kubectl exec -it -n rook-ceph rook-ceph-tools-b8c679f95-pqnnz bash [root@k8s-3 /]# ceph status cluster: id: 04a15e19-c6c3-471d-b552-f8ad39208b51 health: HEALTH_OK services: mon: 2 daemons, quorum a,b (age 69m) mgr: a(active, since 9m) mds: shared-fs:1 {0=shared-fs-b=up:active} 1 up:standby-replay osd: 3 osds: 3 up (since 69m), 3 in (since 2d) data: pools: 3 pools, 300 pgs objects: 116 objects, 271 MiB usage: 3.5 GiB used, 23 GiB / 27 GiB avail pgs: 300 active+clean io: client: 851 B/s rd, 1 op/s rd, 0 op/s wr
  35. 35. Application Deployment
  36. 36. Pod Quality of Service (1) ● Kubernetes 노드에서 필요한 메모리 자원이 부족할 경우 Pod 제거 ○ BestEffort Pod, Burstable Pod 순으로 삭제 ● Guaranteed ○ Pod 안에 있는 모든 컨테이너가 CPU, Memory 자원 Limit & Requests 지정 ○ CPU, Memory 항목별로 Limit 과 Requests 값이 동일 ○ Memory Limit 제한을 넘기 전에는 강제로 종료되지 않음을 보장
  37. 37. Pod Quality of Service (2) ● Burstable ○ Pod 안에 있는 하나 이상의 컨테이너가 CPU 혹은 Memory 자원 Requests 를 가짐 ○ BestEffort Pod 가 하나도 없고, Requests 이상의 자원을 사용할 경우 제거 가능 ● BestEffort ○ Pod 안에 있는 어떤 컨테이너도 Limit 혹은 Requests 를 가지지 않음 ○ Memory 자원이 부족할 경우 먼저 제거되는 Pod
  38. 38. HostPath vs. Local Volume ● HostPath ○ 로컬 디스크를 컨테이너에서 사용할 수 있도록 연결 ○ 노드에 장착되어 있는 디스크를 직접 사용하기 때문에 높은 성능 보장 ○ 컨테이너가 다른 노드로 옮겨갈 경우에 데이터 유실 가능성 ● Local Volume (1.14.x 이상) ○ 로컬 디스크를 컨테이너에 연결해주는 것은 HostPath 와 동일 ○ Pod 와 연결된 Local Volume 을 인식하여 동일 노드에 배포되도록 보장
  39. 39. Deployment: MySQL (1) ● MySQL 에서 사용할 PersistentVolumeClaim 생성 apiVersion: v1 kind: PersistentVolumeClaim metadata: name: mysql-pvc namespace: ghost spec: storageClassName: rook-ceph-block accessModes: - ReadWriteOnce resources: requests: storage: 2Gi
  40. 40. Deployment: MySQL (2) ● Container 항목에 앞에서 생성한 PersistentVolumeClaim 지정 apiVersion: apps/v1 kind: Deployment spec: template: spec: containers: volumeMounts: - name: mysql-persistent-storage mountPath: /var/lib/mysql volumes: - name: mysql-persistent-storage persistentVolumeClaim: claimName: mysql-pvc
  41. 41. Deployment: Ghost (1) ● Ghost 에서 사용할 PersistentVolumeClaim 생성 apiVersion: v1 kind: PersistentVolumeClaim metadata: name: ghost-pvc namespace: ghost spec: storageClassName: rook-ceph-block accessModes: - ReadWriteOnce resources: requests: storage: 1Gi
  42. 42. Deployment: Ghost (2) ● Container 항목에 앞에서 생성한 PersistentVolumeClaim 지정 apiVersion: apps/v1 kind: Deployment spec: template: spec: containers: volumeMounts: - name: ghost-persistent-storage mountPath: /var/lib/ghost/content volumes: - name: ghost-persistent-storage persistentVolumeClaim: claimName: ghost-pvc
  43. 43. Cluster Monitoring
  44. 44. Prometheus ● Prometheus 를 설치해 클러스터 Metric 데이터 수집 ● Helm 을 이용해 설치 가능 ● Prometheus 와 Alertmanager 에서 사용할 Persistent Volume 필요 ○ HostPath 혹은 Local Volume 사용 가능 ○ 네트워크 대역폭이 충분하다면 Ceph 저장소를 연결하는 것도 가능
  45. 45. Grafana (1) ● Prometheus 에서 수집한 데이터를 다양한 Dashboard 로 표현 ○ Kubernetes 클러스터를 보여주는 많은 Dashboard 가 이미 존재 ■ 클러스터 전체적인 Metric 을 보여주는 Dashboard ■ Pod 상태를 보여주는 Dashboard ■ 노드 별 상태를 보여주는 Dashboard ● 내부 데이터를 저장하는데 사용할 Persistent Volume 필요 ○ HostPath 혹은 Local Volume 사용 가능 ○ Metric 데이터를 직접 저장하지 않기 때문에 Ceph 저장소도 고려해 볼만함
  46. 46. Grafana (2)
  47. 47. Filebeat ● DaemonSet 형태로 모든 노드에 배포 ● 다양한 로그 수집 ○ Kubernetes 노드에 쌓이는 syslog, auth 관련 ○ 컨테이너에서 기록하는 로그 ● 수집한 로그를 Elasticsearch 로 전달 ○ 전달 전에 로그 안에서 불필요한 내용 제거 ■ INFO, DEBUG 로그 제외 ■ 테스트 목적을 가진 Namespace 에서 생성한 로그 등
  48. 48. Metricbeat (1) ● DaemonSet 형태로 모든 노드에 배포 ● 시스템, 컨테이너, Kubernetes 상태 Metric 정보 수집 ○ CPU, Load, Memory, Network, Process ○ Node, Pod, Container, Volume ● Kibana Infrastructure 기능을 통해 컨테이너 세부 Metric 정보 확인 가능
  49. 49. Metricbeat (2) ● Kubernetes Metric 수집 설정 kubernetes.yml: |- - module: kubernetes metricsets: - node - system - pod - container - volume period: 10s host: ${NODE_NAME} hosts: ["localhost:10255"]
  50. 50. Metricbeat (3) ● Kubelet 정보 수집을 위해 Read-Only-Port 열기 (기본값: 비활성화) ● /var/lib/kubelet/kubeadm-flags.env 파일에 옵션 추가 ● Kubelet 재시작 KUBELET_KUBEADM_ARGS=--cgroup-driver=cgroupfs --network-plugin=cni --pod- infra-container-image=k8s.gcr.io/pause:3.1 --read-only-port 10255 sudo systemctl restart kubelet
  51. 51. Elasticsearch & Kibana ● 수집한 로그를 Kibana 에서 확인 ● 원하는 키워드로 검색 가능 ● Elasticsearch 를 배포할 때 Persistent Volume 사용 ○ HostPath 혹은 Local Volume 사용 가능 ○ 외부 Elasticsearch 클러스터도 괜찮은 구성 ● Kibana Log 기능을 통해 원본 로그 확인 가능
  52. 52. Kibana: Discover
  53. 53. Kibana: Log
  54. 54. Infrastructure: Kubernetes Pods
  55. 55. Infrastructure: Docker Containers
  56. 56. NexClipper ● Open-Source Kubernetes Monitoring Service ○ https://github.com/NexClipper/NexClipper ● NexclipperAgent 를 DaemonSet 형태로 모든 노드에 배포 ● Agent 에서 보내주는 데이터 수집 ● 클러스터 Host, Container 등에서 Metric 데이터 수집 ● Kubernetes Workloads Metric 데이터 수집 ● Incident Manager 에 RuleSet 설정을 통해 중요 이벤트 검출 가능
  57. 57. NexClipper: Dashboard
  58. 58. NexClipper: Cluster
  59. 59. NexClipper: Host
  60. 60. NexClipper: Pod
  61. 61. NexClipper: Container
  62. 62. Demo #1 Kubernetes Cluster #2 Application #3 Monitoring
  63. 63. Summary ● Multi Master Nodes 는 클러스터 구축 시에 같이 ○ Etcd 클러스터 유효 노드 수 ((n / 2) + 1) 유지하는 것이 매우 중요 ● Network Add-on 에서 사용하는 IP 대역과 노드 IP 대역 겹치지 않도록 ● 노드 규모가 크다면 Proxy Mode 로 ipvs 고려 ○ MetalLB 를 사용한다면 같이 동작하는지 테스트 필요 ● Rook & Ceph 를 이용해 동적 Persistent Volume 사용 가능 ● 다양한 Monitoring 방법 적용
  64. 64. 감사합니다 임찬식 chanshik@gmail.com

×