
이 블로그는 여러 파트로 구성된 블로그 시리즈의 일부로, Kubernetes에서 애플리케이션을 실행하는 방법을 보여줍니다. 이 블로그는 카우치베이스오픈 소스 NoSQL 분산 문서 데이터베이스를 Docker 컨테이너로 사용합니다.
첫 번째 부분(쿠버네티스의 카우치베이스)에서는 Vagrant를 사용하여 Kubernetes 클러스터를 시작하는 방법을 설명했습니다. 두 번째 부분(아마존의 쿠버네티스)에서 해당 설정을 실행하는 방법을 설명합니다.
이 세 번째 파트에서 보여드릴 내용입니다:
- Google Cloud에서 Kubernetes 클러스터를 설정하고 시작하는 방법
- 쿠버네티스 클러스터에서 도커 컨테이너 실행하기
- 쿠버네티스에서 파드를 서비스로 노출하기
- 클러스터 종료
다음은 간단한 개요입니다:
자세히 알아보겠습니다!
Google 컴퓨팅 엔진 시작하기 에서는 Google Cloud에서 Kubernetes를 설정하는 방법에 대한 자세한 지침을 제공합니다.
Google Cloud SDK 다운로드 및 구성
컴퓨터에서 Google 클라우드에 액세스한 적이 없는 경우 약간의 설정이 필요합니다. 이 과정이 다소 번거로웠지만 간소화되었으면 좋겠습니다.
- 다음에서 청구 가능한 계정을 만듭니다. Google 클라우드
- 설치 Google 클라우드 SDK
- 자격 증명 구성: gcloud 인증 로그인
- 새 Google Cloud 프로젝트를 만들고 이름을 지정합니다.
카우치베이스-온-쿠버네티스 - 프로젝트를 설정합니다:
gcloud 구성 설정 프로젝트 카우치베이스-온-쿠버네티스 프로젝트 - 기본 영역을 설정합니다:
gcloud 구성 설정 컴퓨트/영역 US-CENTRAL1-A - 인스턴스를 만듭니다:
gcloud compute 인스턴스 생성 예제 인스턴스 --machine-type n1-standard-1 --image debian-8 - 인스턴스에 접속합니다:
gcloud 컴퓨트 SSH 예제 인스턴스 - 인스턴스를 삭제합니다:
gcloud 컴퓨트 인스턴스 삭제 예제 인스턴스
Google Cloud에서 Kubernetes 클러스터 설정하기
Kubernetes 클러스터는 Google Cloud에서 다음과 같이 만들 수 있습니다:
|
1 2 |
set KUBERNETES_PROVIDER=gce ./cluster/kube-up.sh |
다음 사항을 확인하십시오. 쿠버네티스_프로바이더 로 설정되어 있거나 gce 로 설정하거나 전혀 설정하지 않습니다. 기본적으로 마스터가 하나 있는 4노드 Kubernetes 클러스터를 프로비저닝합니다. 즉, 5개의 가상 머신이 생성됩니다.
다음에서 Kubernetes를 다운로드한 경우 github.com/kubernetes/kubernetes/releases에서 모든 값을 변경할 수 있습니다. cluster/aws/config-default.sh.
Google Cloud에서 Kubernetes를 시작하면 다음 로그가 표시됩니다. Google Cloud SDK가 약간 이상하게 동작했지만 기본값을 사용하면 작동하는 것 같습니다:
|
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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
./kubernetes/cluster/kube-up.sh ... Starting cluster using provider: gce ... calling verify-prereqs You have specified individual components to update. If you are trying to install new components, use: $ gcloud components install alpha Do you want to run install instead (y/N)? Your current Cloud SDK version is: 99.0.0 Installing components from version: 99.0.0 ┌──────────────────────────────────────────────┐ │ These components will be installed. │ ├───────────────────────┬────────────┬─────────┤ │ Name │ Version │ Size │ ├───────────────────────┼────────────┼─────────┤ │ gcloud Alpha Commands │ 2016.01.12 │ < 1 MiB │ └───────────────────────┴────────────┴─────────┘ For the latest full release notes, please visit: https://cloud.google.com/sdk/release_notes Do you want to continue (Y/n)? ╔════════════════════════════════════════════════════════════╗ ╠═ Creating update staging area ═╣ ╠════════════════════════════════════════════════════════════╣ ╠═ Installing: gcloud Alpha Commands ═╣ ╠════════════════════════════════════════════════════════════╣ ╠═ Creating backup and activating new installation ═╣ ╚════════════════════════════════════════════════════════════╝ Performing post processing steps...done. Update done! You have specified individual components to update. If you are trying to install new components, use: $ gcloud components install beta Do you want to run install instead (y/N)? Your current Cloud SDK version is: 99.0.0 Installing components from version: 99.0.0 ┌─────────────────────────────────────────────┐ │ These components will be installed. │ ├──────────────────────┬────────────┬─────────┤ │ Name │ Version │ Size │ ├──────────────────────┼────────────┼─────────┤ │ gcloud Beta Commands │ 2016.01.12 │ < 1 MiB │ └──────────────────────┴────────────┴─────────┘ For the latest full release notes, please visit: https://cloud.google.com/sdk/release_notes Do you want to continue (Y/n)? ╔════════════════════════════════════════════════════════════╗ ╠═ Creating update staging area ═╣ ╠════════════════════════════════════════════════════════════╣ ╠═ Installing: gcloud Beta Commands ═╣ ╠════════════════════════════════════════════════════════════╣ ╠═ Creating backup and activating new installation ═╣ ╚════════════════════════════════════════════════════════════╝ Performing post processing steps...done. Update done! All components are up to date. ... calling kube-up Your active configuration is: [default] Project: couchbase-on-kubernetes Zone: us-central1-b Creating gs://kubernetes-staging-9479406781 Creating gs://kubernetes-staging-9479406781/... +++ Staging server tars to Google Storage: gs://kubernetes-staging-9479406781/devel +++ kubernetes-server-linux-amd64.tar.gz uploaded (sha1 = 1ff42f7c31837851d919a66fc07f34b9dbdacf28) +++ kubernetes-salt.tar.gz uploaded (sha1 = f307380ad6af7dabcf881b132146fa775c18dca8) Looking for already existing resources Starting master and configuring firewalls Created [https://www.googleapis.com/compute/v1/projects/couchbase-on-kubernetes/zones/us-central1-b/disks/kubernetes-master-pd]. NAME ZONE SIZE_GB TYPE STATUS kubernetes-master-pd us-central1-b 20 pd-ssd READY Created [https://www.googleapis.com/compute/v1/projects/couchbase-on-kubernetes/regions/us-central1/addresses/kubernetes-master-ip]. Created [https://www.googleapis.com/compute/v1/projects/couchbase-on-kubernetes/global/firewalls/default-default-ssh]. Created [https://www.googleapis.com/compute/v1/projects/couchbase-on-kubernetes/global/firewalls/kubernetes-master-https]. NAME NETWORK SRC_RANGES RULES SRC_TAGS TARGET_TAGS default-default-ssh default 0.0.0.0/0 tcp:22 NAME NETWORK SRC_RANGES RULES SRC_TAGS TARGET_TAGS kubernetes-master-https default 0.0.0.0/0 tcp:443 kubernetes-master +++ Logging using Fluentd to gcp ./kubernetes/cluster/../cluster/../cluster/gce/util.sh: line 434: @: unbound variable ./kubernetes/cluster/../cluster/../cluster/gce/util.sh: line 434: @: unbound variable ./kubernetes/cluster/../cluster/../cluster/gce/util.sh: line 434: @: unbound variable ./kubernetes/cluster/../cluster/../cluster/gce/util.sh: line 434: @: unbound variable Created [https://www.googleapis.com/compute/v1/projects/couchbase-on-kubernetes/global/firewalls/default-default-internal]. NAME NETWORK SRC_RANGES RULES SRC_TAGS TARGET_TAGS default-default-internal default 10.0.0.0/8 tcp:1-65535,udp:1-65535,icmp Created [https://www.googleapis.com/compute/v1/projects/couchbase-on-kubernetes/global/firewalls/kubernetes-minion-all]. NAME NETWORK SRC_RANGES RULES SRC_TAGS TARGET_TAGS kubernetes-minion-all default 10.244.0.0/16 tcp,udp,icmp,esp,ah,sctp kubernetes-minion Created [https://www.googleapis.com/compute/v1/projects/couchbase-on-kubernetes/zones/us-central1-b/instances/kubernetes-master]. NAME ZONE MACHINE_TYPE PREEMPTIBLE INTERNAL_IP EXTERNAL_IP STATUS kubernetes-master us-central1-b n1-standard-1 10.128.0.2 104.197.213.249 RUNNING Creating minions. ./kubernetes/cluster/../cluster/../cluster/gce/util.sh: line 434: @: unbound variable ./kubernetes/cluster/../cluster/../cluster/gce/util.sh: line 434: @: unbound variable Attempt 1 to create kubernetes-minion-template WARNING: You have selected a disk size of under [200GB]. This may result in poor I/O performance. For more information, see: https://developers.google.com/compute/docs/disks/persistent-disks#pdperformance. Created [https://www.googleapis.com/compute/v1/projects/couchbase-on-kubernetes/global/instanceTemplates/kubernetes-minion-template]. NAME MACHINE_TYPE PREEMPTIBLE CREATION_TIMESTAMP kubernetes-minion-template n1-standard-1 2016-03-03T14:01:14.322-08:00 Created [https://www.googleapis.com/compute/v1/projects/couchbase-on-kubernetes/zones/us-central1-b/instanceGroupManagers/kubernetes-minion-group]. NAME ZONE BASE_INSTANCE_NAME SIZE TARGET_SIZE INSTANCE_TEMPLATE AUTOSCALED kubernetes-minion-group us-central1-b kubernetes-minion 4 kubernetes-minion-template Waiting for group to become stable, current operations: creating: 4 Waiting for group to become stable, current operations: creating: 4 Waiting for group to become stable, current operations: creating: 4 Waiting for group to become stable, current operations: creating: 4 Waiting for group to become stable, current operations: creating: 4 Waiting for group to become stable, current operations: creating: 4 Waiting for group to become stable, current operations: creating: 3 Group is stable MINION_NAMES=kubernetes-minion-1hmm kubernetes-minion-3x1d kubernetes-minion-h1ov kubernetes-minion-nshn Using master: kubernetes-master (external IP: 104.197.213.249) Waiting for cluster initialization. This will continually check to see if the API for kubernetes is reachable. This might loop forever if there was some uncaught error during start up. Kubernetes cluster created. cluster "couchbase-on-kubernetes_kubernetes" set. user "couchbase-on-kubernetes_kubernetes" set. context "couchbase-on-kubernetes_kubernetes" set. switched to context "couchbase-on-kubernetes_kubernetes". user "couchbase-on-kubernetes_kubernetes-basic-auth" set. Wrote config for couchbase-on-kubernetes_kubernetes to /Users/arungupta/.kube/config Kubernetes cluster is running. The master is running at: https://104.197.213.249 The user name and password to use is located in /Users/arungupta/.kube/config. ... calling validate-cluster Waiting for 4 ready nodes. 0 ready nodes, 0 registered. Retrying. Waiting for 4 ready nodes. 0 ready nodes, 2 registered. Retrying. Waiting for 4 ready nodes. 0 ready nodes, 3 registered. Retrying. Waiting for 4 ready nodes. 0 ready nodes, 4 registered. Retrying. Waiting for 4 ready nodes. 3 ready nodes, 4 registered. Retrying. Waiting for 4 ready nodes. 3 ready nodes, 4 registered. Retrying. Found 4 node(s). NAME LABELS STATUS AGE kubernetes-minion-1hmm kubernetes.io/hostname=kubernetes-minion-1hmm Ready 1m kubernetes-minion-3x1d kubernetes.io/hostname=kubernetes-minion-3x1d Ready 52s kubernetes-minion-h1ov kubernetes.io/hostname=kubernetes-minion-h1ov Ready 1m kubernetes-minion-nshn kubernetes.io/hostname=kubernetes-minion-nshn Ready 1m Validate output: NAME STATUS MESSAGE ERROR controller-manager Healthy ok nil scheduler Healthy ok nil etcd-0 Healthy {"health": "true"} nil etcd-1 Healthy {"health": "true"} nil Cluster validation succeeded Done, listing cluster services: Kubernetes master is running at https://104.197.213.249 GLBCDefaultBackend is running at https://104.197.213.249/api/v1/proxy/namespaces/kube-system/services/default-http-backend Heapster is running at https://104.197.213.249/api/v1/proxy/namespaces/kube-system/services/heapster KubeDNS is running at https://104.197.213.249/api/v1/proxy/namespaces/kube-system/services/kube-dns KubeUI is running at https://104.197.213.249/api/v1/proxy/namespaces/kube-system/services/kube-ui Grafana is running at https://104.197.213.249/api/v1/proxy/namespaces/kube-system/services/monitoring-grafana InfluxDB is running at https://104.197.213.249/api/v1/proxy/namespaces/kube-system/services/monitoring-influxdb |
몇 개의 바인딩되지 않은 변수와 경고 메시지가 있지만 스크립트가 손상되지는 않은 것 같습니다. Google 클라우드 콘솔을 보여줍니다: 
그림과 같이 마스터 노드용 인스턴스 1개와 워커 노드용 인스턴스 4개 등 총 5개의 인스턴스가 생성됩니다.
구글 클라우드의 쿠버네티스 클러스터에서 도커 컨테이너 실행하기
이제 클러스터가 실행 중이므로 모든 노드 목록을 가져옵니다:
|
1 2 3 4 5 6 |
./kubernetes/cluster/kubectl.sh get no NAME LABELS STATUS AGE kubernetes-minion-1hmm kubernetes.io/hostname=kubernetes-minion-1hmm Ready 47m kubernetes-minion-3x1d kubernetes.io/hostname=kubernetes-minion-3x1d Ready 46m kubernetes-minion-h1ov kubernetes.io/hostname=kubernetes-minion-h1ov Ready 47m kubernetes-minion-nshn kubernetes.io/hostname=kubernetes-minion-nshn Ready 47m |
4개의 워커 노드가 표시됩니다. 카우치베이스 파드를 생성합니다:
|
1 2 |
./kubernetes/cluster/kubectl.sh run couchbase --image=arungupta/couchbase replicationcontroller "couchbase" created |
CLI에서 이미지 이름을 지정하는 방법에 주목하세요. 이 명령은 단일 파드가 있는 리플리케이션 컨트롤러를 생성합니다. 이 파드는 아룽업타/카우치베이스 사전 구성된 Couchbase 서버를 제공하는 Docker 이미지입니다. 모든 Docker 이미지를 여기에 지정할 수 있습니다.
모든 RC 리소스를 확인하세요:
|
1 2 3 |
./kubernetes/cluster/kubectl.sh get rc CONTROLLER CONTAINER(S) IMAGE(S) SELECTOR REPLICAS AGE couchbase couchbase arungupta/couchbase run=couchbase 1 48s |
그러면 생성된 복제 컨트롤러가 표시됩니다.
모든 파드를 가져옵니다:
|
1 2 3 |
./kubernetes/cluster/kubectl.sh get po NAME READY STATUS RESTARTS AGE couchbase-s8v9r 1/1 Running 0 1m |
출력에는 리플리케이션 컨트롤러의 일부로 생성된 파드가 표시됩니다.
Pod에 대해 자세히 알아보세요:
|
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 39 40 41 42 43 44 |
./kubernetes/cluster/kubectl.sh describe po couchbase-s8v9r Name: couchbase-s8v9r Namespace: default Image(s): arungupta/couchbase Node: kubernetes-minion-3x1d/10.128.0.3 Start Time: Thu, 03 Mar 2016 14:53:36 -0800 Labels: run=couchbase Status: Running Reason: Message: IP: 10.244.3.3 Replication Controllers: couchbase (1/1 replicas created) Containers: couchbase: Container ID: docker://601ee2e4c822814c3969a241e37c97bf4d0d209f952f24707ab308192d289098 Image: arungupta/couchbase Image ID: docker://298618e67e495c2535abd17b60241565e456a4c9ee96c923ecf844a9dbcccced QoS Tier: cpu: Burstable Requests: cpu: 100m State: Running Started: Thu, 03 Mar 2016 14:54:46 -0800 Ready: True Restart Count: 0 Environment Variables: Conditions: Type Status Ready True Volumes: default-token-frsd7: Type: Secret (a secret that should populate this volume) SecretName: default-token-frsd7 Events: FirstSeen LastSeen Count From SubobjectPath Reason Message ───────── ──────── ───── ──── ───────────── ────── ─────── 1m 1m 1 {kubelet kubernetes-minion-3x1d} implicitly required container POD Pulled Container image "gcr.io/google_containers/pause:0.8.0" already present on machine 1m 1m 1 {scheduler } Scheduled Successfully assigned couchbase-s8v9r to kubernetes-minion-3x1d 1m 1m 1 {kubelet kubernetes-minion-3x1d} implicitly required container POD Created Created with docker id c1de9da87f1e 1m 1m 1 {kubelet kubernetes-minion-3x1d} spec.containers{couchbase} Pulling Pulling image "arungupta/couchbase" 1m 1m 1 {kubelet kubernetes-minion-3x1d} implicitly required container POD Started Started with docker id c1de9da87f1e 29s 29s 1 {kubelet kubernetes-minion-3x1d} spec.containers{couchbase} Pulled Successfully pulled image "arungupta/couchbase" 29s 29s 1 {kubelet kubernetes-minion-3x1d} spec.containers{couchbase} Created Created with docker id 601ee2e4c822 29s 29s 1 {kubelet kubernetes-minion-3x1d} spec.containers{couchbase} Started Started with docker id 601ee2e4c822 |
쿠버네티스에서 파드를 서비스로 노출하기
이제 파드가 실행 중인데, Couchbase 서버에 어떻게 액세스하나요? 쿠버네티스 클러스터 외부에 노출시켜야 합니다. 쿠버네티스 클러스터의 kubectl 노출 명령은 파드, 서비스 또는 리플리케이션 컨트롤러를 가져와서 쿠버네티스 서비스로 노출합니다.
이전에 생성한 복제 컨트롤러를 노출해 보겠습니다:
|
1 2 |
./kubernetes/cluster/kubectl.sh expose rc couchbase --target-port=8091 --port=8091 --type=LoadBalancer service "couchbase" exposed |
서비스에 대해 자세히 알아보세요:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
./kubernetes/cluster/kubectl.sh describe svc couchbase Name: couchbase Namespace: default Labels: run=couchbase Selector: run=couchbase Type: LoadBalancer IP: 10.0.37.150 LoadBalancer Ingress: 104.197.118.35 Port: 8091/TCP NodePort: 30808/TCP Endpoints: 10.244.3.3:8091 Session Affinity: None Events: FirstSeen LastSeen Count From SubobjectPath Reason Message ───────── ──────── ───── ──── ───────────── ────── ─────── 2m 2m 1 {service-controller } CreatingLoadBalancer Creating load balancer 1m 1m 1 {service-controller } CreatedLoadBalancer Created load balancer |
그리고 로드밸런서 인그레스 속성은 이제 공개적으로 액세스할 수 있는 로드 밸런서의 IP 주소를 제공합니다. 로드 밸런서가 안정화될 때까지 3분 정도 기다립니다. 포트 8091을 사용하여 액세스하면 Couchbase 웹 콘솔의 로그인 페이지가 표시됩니다: 
웹 콘솔을 보려면 '관리자' 및 '비밀번호'로 자격 증명을 입력합니다: 
그래서 방금 쿠버네티스 클러스터 외부에서 파드에 액세스했습니다.
쿠버네티스 클러스터 종료
마지막으로 다음을 사용하여 클러스터를 종료합니다. cluster/kube-down.sh 스크립트.
|
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 39 40 41 |
./kubernetes/cluster/kube-down.sh Bringing down cluster using provider: gce You have specified individual components to update. If you are trying to install new components, use: $ gcloud components install alpha Do you want to run install instead (y/N)? All components are up to date. You have specified individual components to update. If you are trying to install new components, use: $ gcloud components install beta Do you want to run install instead (y/N)? All components are up to date. All components are up to date. Your active configuration is: [default] Project: couchbase-on-kubernetes Zone: us-central1-b Bringing down cluster Deleted [https://www.googleapis.com/compute/v1/projects/couchbase-on-kubernetes/zones/us-central1-b/instanceGroupManagers/kubernetes-minion-group]. Deleted [https://www.googleapis.com/compute/v1/projects/couchbase-on-kubernetes/global/instanceTemplates/kubernetes-minion-template]. Updated [https://www.googleapis.com/compute/v1/projects/couchbase-on-kubernetes/zones/us-central1-b/instances/kubernetes-master]. Deleted [https://www.googleapis.com/compute/v1/projects/couchbase-on-kubernetes/zones/us-central1-b/instances/kubernetes-master]. Deleted [https://www.googleapis.com/compute/v1/projects/couchbase-on-kubernetes/global/firewalls/kubernetes-master-https]. Deleted [https://www.googleapis.com/compute/v1/projects/couchbase-on-kubernetes/global/firewalls/kubernetes-minion-all]. Deleting routes kubernetes-ad3beb92-e18b-11e5-8e71-42010a800002 Deleted [https://www.googleapis.com/compute/v1/projects/couchbase-on-kubernetes/global/routes/kubernetes-ad3beb92-e18b-11e5-8e71-42010a800002]. Deleted [https://www.googleapis.com/compute/v1/projects/couchbase-on-kubernetes/regions/us-central1/addresses/kubernetes-master-ip]. property "clusters.couchbase-on-kubernetes_kubernetes" unset. property "users.couchbase-on-kubernetes_kubernetes" unset. property "users.couchbase-on-kubernetes_kubernetes-basic-auth" unset. property "contexts.couchbase-on-kubernetes_kubernetes" unset. property "current-context" unset. Cleared config for couchbase-on-kubernetes_kubernetes from /Users/arungupta/.kube/config Done |
즐기세요!
