본문 바로가기

[DevOps]/[Kubernetes]

[Qwiklabs] Kubernetes in Google Cloud [ Orchestrating the Cloud with Kubernetes ]

728x90

[ Orchestrating the Cloud with Kubernetes ]

kubernetes.io

 

Production-Grade Container Orchestration

Kubernetes (K8s) is an open-source system for automating deployment, scaling, and management of containerized applications. It groups containers that make up an application into logical units for easy management and discovery. Kubernetes builds upon 15 yea

kubernetes.io

이번 실습은 내용이 상당히 많았다. 배우는 내용은 다음과 같다. kubernetes cluster를 준비해 두었다가 필요할때 제공하는 것, kubectl로 docker container를 배포하고 관리하는 것, applicaiton을 micro services로 쪼개는 것이다. 하나하나가 중요하고 재밌어 보이는 내용이다.

  • Provision a complete  Kubernetes cluster using  Kubernetes Engine.
  • Deploy and manage Docker containers using kubectl.
  • Break an application into microservices using Kubernetes' Deployments and Services.

또한 실습에서 사용할 docker image에 관한 정보는 다음과 같다.

 

Set up requirement)

먼저 기본적으로 컴퓨트 존을 설정한다. 다음으로 cluster를 생성해준다. 

gcloud config set compute/zone us-central1-b

gcloud container clusters create io

Get the sample code)

이어서 미리 qwiklab측에서 생성해놓은 깃 레퍼지토리를 클론해온다. 

git clone https://github.com/googlecodelabs/orchestrate-with-kubernetes.git
cd orchestrate-with-kubernetes/kubernetes

 

Quick Kubernetes Demo)

쿠버테티스를 시작하는 가장 쉬운 방법은 kubectl명령어를 사용하는 것이다. 

kubectl create deployment nginx --image=nginx:1.10.0

kubertetes에서 모든 컨테이너들은 pod안에서 운용된다. 아래 사진들은 그 결과물을 보여주는 것이며, pod에 대한 설명은 pods)에 있다.

kubectl get pods

Pods)

kubernetes.io/docs/concepts/workloads/pods/pod/

 

Pods

 

kubernetes.io

 만약 복수개의 container들이 서로 매우 밀접한 관계에 있는 경우, 이들 컨테이너들을 단일 pod안에 넣어 관리하곤 한다. 아래 이미지는 monolith and nginx container가 단일 pod 내에 생성되어 있는 모습니다. 

Creating Pods)

cat pods/monolith.yaml

위 명령어는 pod를 생성하는 yaml파일을 나타낸 것으로, 구체적인 파일의 내용은 아래와 같다. 

apiVersion: v1
kind: Pod
metadata:
  name: monolith
  labels:
    app: monolith
spec:
  containers:
    - name: monolith
      image: kelseyhightower/monolith:1.0.0
      args:
        - "-http=0.0.0.0:80"
        - "-health=0.0.0.0:81"
        - "-secret=secret"
      ports:
        - name: http
          containerPort: 80
        - name: health
          containerPort: 81
      resources:
        limits:
          cpu: 0.2
          memory: "10Mi"

이 파일을 이용해서 pod를 생성하려면 단순히 아래의 명령어로 가능하다.

kubectl create -f pods/monolith.yaml

 

Interacting with Pods)

pod내부와 외부의 interaction을 위해 port를 개방하는 내용이다. 포스팅에는 생략하도록 한다.

Services)

'복수개의 pod가 서로 통신하기 위해서는 어떻게 해야할까? 이를 위해 도입된 개념이 'Services'이다. 이 'services'는 pod에게 안정적인 endpoint를 제공한다. 또한 동일 라벨링이 되어있는 pod들을 자동적으로 관리하게 된다. 

Services use labels to determine what Pods they operate on. If Pods have the correct labels, they are automatically picked up and exposed by our services.

The level of access a service provides to a set of pods depends on the Service's type. Currently there are three types:

  • ClusterIP (internal) -- the default type means that this Service is only visible inside of the cluster,
  • NodePort gives each node in the cluster an externally accessible IP and
  • LoadBalancer adds a load balancer from the cloud provider which forwards traffic from the service to Nodes within it

Creating a Service)

 

Adding Labels to Pods)

Deploying Applications with Kubernetes)

Creating Deployments)

 

728x90