SlideShare ist ein Scribd-Unternehmen logo
1 von 27
Downloaden Sie, um offline zu lesen
CNC	&	Kubernetes	Meetup	(March 2018)
안승규	
ahnsk@sk.com	
seungkyua@gmail.com
Kubernetes & Helm 활용
2
Kubernetes Resources
4
[ Pod ]
• 컨테이너를 담고 있는 그릇 (여러개의 컨테이너가 포함될 수 있음)
• 같은 Pods 안에서의 여러 컨테이너가 같은 네트워크 네임스페이스와 ip 를 가짐
(Apache -> (localhost, port) -> Tomcat)
• 같은 Pods 안에서의 여러 컨테이너가 같은 볼륨을 볼 수 있음
[ ReplicaSet ]
• Pod 개수를 관리
[ Deployment ]
• Pod 와 Replica Set 을 통합하여 배포할 수 있는 단위
• 배포 히스토리를 버전별로 관리
[ Service ]
• Route to pod (using labels) – 내부 IP로 Pod 에 대한 Load Balancing (기본기능)
• 외부에서 접근할려면 아래 두 타입을 활용하여 가능
• 타입 : Load balancer (GCE), NodePort (iptables)
[ ConfigMap and Secret ]
• ConfigMap : Application 의 Configuration, 혹은 shell script
• Secret : 보안 값
3
Pod
3
• 컨테이너 배포 단위로 컨테이너를 담고 있는 그릇
• 여러 개의 컨테이너가 포함될 수 있음
• 하나의 Pod 안에서의 여러 컨테이너는 같은 docker ip 를
가짐
• pause 컨테이너가 하나씩 생김
• Pod 내부에서 컨테이너간 통신은 localhost & 포트로 통신
• Docker Networking 의 Mapped Container Mode
docker run -d --name pause pause_image
docker run -d --name web -net=container:pause
web_image
• 하나의 Pods 안에서의 여러 컨테이너는 같은 볼륨을 볼 수
있다.
4
ReplicaSet
44
• Pod 의 개수를 지정해서 실행
• 실행 중인 Pod 의 수를 항상 보장
• Pod 를 명령어로 삭제해도 ReplicaSet 에 의해 자동 복구됨
• Horizontal Pod Autoscaler 가 autoscale 을 할 때 ReplicaSet 활용
• ReplicaSet = Pod + replicas 수 (Pod 개수)
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
name: frontend-scaler
spec:
scaleTargetRef:
apiVersion: apps/v1beta1
kind: Deployment
name: frontend
minReplicas: 3
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
targetAverageUtilization: 50
Deployment
7
• Deployment = ReplicaSet + History (Revision)
• Pod 배포에 대한 버전 관리가 가능
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
namespace: default
spec:
replicas: 3
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.7.9
ports:
- containerPort: 80
$ kubectl create -f nginx.yaml
$ kubectl rollout history deployment/nginx-
deployment
$ kubectl rollout history deployment/nginx-
deployment --revision=2
$ kubectl rollout undo deployment/nginx-
deployment --to-revision=2
Service
8
• Type: ClusterIP(default), LoadBalancer, NodePort, ExternalName
• Pod 를 대표하는 DNS 이름
• ClusterIP 가 할당됨 (Virtual IP)
• kube-proxy 가 iptables 에 Cluster IP 세팅
• Simple Load Balance (default : Round Robin)
• selector 를 지정하면 Endpoint 가 생김
Service
Pod B-1 Pod B-2
Pod A-1
serivce명 & port
Pod IP & port (Endpoint)
apiVersion: v1
kind: Service
metadata:
name: frontend
labels:
app: guestbook
tier: frontend
spec:
type: NodePort
ports:
- port: 80
nodePort: 31000
selector:
app: guestbook
tier: frontend
7
What is Helm?
The	package	manager	for	Kubernetes
Helm	helps	you	manage	Kubernetes	applications	- Helm	Charts	
helps	you	define,	install,	and	upgrade	even	the	most	complex	
Kubernetes	application.
Charts	are	easy	to	create,	version,	share,	and	publish	- so	start	
using	Helm	and	stop	the	copy-and-paste	madness.
Helm 특징
Manage	Complexity
Charts	describe	even	the	most	complex	apps;	provide	repeatable	
application	installation,	and	serve	as	a	single	point	of	authority.
Easy	Updates
Take	the	pain	out	of	updates	with	in-place	upgrades	and	custom	hooks.
Simple	Sharing
Charts	are	easy	to	version,	share,	and	host	on	public	or	private	servers.
Rollbacks
Use	helm	rollback	to	roll	back	to	an	older	version	of	a	release	with	ease.
kubectl rollout
$	kubectl	rollout	history	daemonset/abc	(--revision=3)
$	Kubectl	rollout	undo	daemonset/abc	--to-revision=3
$	helm	history	mariadb-default
$	helm	rollback	mariadb-default	1
Helm Architecture
Helm Client
Kubernetes	Cluster
Tiller Server
Kube-api
① Authentication
Chart
③ Installing chart
② Request to install
(gRPC)
Manifest file
Helm Architecture
Helm	Client
• a	command-line	client	for	end	users.
• Managing	repositories
• Interacting	with	the	Tiller	server
• Sending charts to be installed
• Asking for information about releases
• Requesting upgrading or uninstalling of existing releases
Tiller	Server
• an	in-cluster	server	that	interacts	with	the	Helm	client,	and	interfaces	
with	the	Kubernetes	API	server.
• Listening for incoming requests from the Helm client
• Combining a chart and configuration to build a release
• Installing charts into Kubernetes, and then tracking the
subsequent release
• Upgrading and uninstalling charts by interacting with
Kubernetes
Simple chart 생성
$ helm create mychart
mychart/
├── charts/
├── Chart.yaml
├── templates/
│ ├── deployment.yaml
│ ├── _helpers.tpl
│ ├── ingress.yaml
│ ├── NOTES.txt
│ └── service.yaml
└── values.yaml
helm install 시에 디스플레이 되는 문장
kubernetes 기본 manifest 파일
kubernetes service manifest 파일
template helper, utililty function 처럼
동작
tiller 가 templates rendering engine 을 통해 generation
chart version 등 chart 에 대한 설명을 담고 있음
subcharts 라 부르는 다른 chart를 포함할 수 있는 디렉토리
kubernetes ingress manifest 파일
chart에 대한 기본 값을 저장, 변수처럼 활용
helm install 이나 helm upgrade 시에 override 가능
Template directive
$ vi mychart/templates/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}-configmap
data:
myvalue: "Hello World"
- Template 지시자는 {{ }} 로 표시
- Value 가 template 안에서 치환되며 dot( . ) 으로 시작하여 namespace 를 넣을 수 있다.
- 맨처음의 dot 은 최상의 네임스페이스를 의미하며 Release 는 내장 (built-in) 객체로서 Name
객체를 가지고 있다.
$ helm install ./mychart
$ kubectl	get	configmap
NAME																													DATA						AGE
iced-bear-configmap 1													19s
$ helm get manifest iced-bear
$ helm	delete	iced-bear
Build-in Objects
Release
{{	.Release.Name	}},	{{	.Release.Namespace	}},	{{	.Release.Service	}}	
{{	.Release.Revision	}},	{{	.Release.IsUpgrade	}},	{{	.Release.IsInstall	}}	
Values
values.yaml 파일에 정의된 값 (직접 수정하거나 Override	할 수 있는 값)
{{	.Values.xxx	}}
Chart
{{	.Chart.Name	}},	{{	.Chart.Version	}}
Template
{{	.Template.Name	}}	:	현재 template	파일명
{{	.Template.BasePath	}}	:	template	디렉토리 경로
Files,	Capabilities
Values File
$ vi mychart/values.yaml
favoriteDrink: coffee
$ vi	mychart/templates/configmap.yaml
apiVersion:	v1
kind:	ConfigMap
metadata:
name:	{{	.Release.Name	}}-configmap
data:
myvalue:	"Hello	World"
drink:	{{	.Values.favoriteDrink }}
$ helm	install	./mychart	
NAME:			needled-rottweiler
LAST	DEPLOYED:	Fri	Feb	23	04:57:15	2018
NAMESPACE:	default
STATUS:	DEPLOYED
RESOURCES:
==>	v1/ConfigMap
NAME																										DATA		AGE
needled-rottweiler-configmap		2					0s
Ø values.yaml 파일 위치는 chart 최상위 디렉토리에 위치 (e.g. ./mychart/values.yaml)
Ø helm install 혹은 helm upgrade 시에 -f 로 override 가능
Ø --set key=value 로 value override 가능
Template
"{{23 -}} < {{- 45}}" 는 "23<45" 와 같이 공백없이 출력
Ø "{{-" 은 text 앞의 공백을 없앤다.
Ø "-}}" 은 text 뒤의 공백을 없앤다.
Ø {{/* a comment */}} : 주석 처리
Ø {{pipeline}} : 값 print
Ø {{if pipeline}} T1 {{end}}
pipeline 값이 empty가 아니면 T1 수행
empty 정의 : false, 0, nil 그리고 array, slice, map, string 의 길이가 0
Ø {{if pipeline}} T1 {{else}} T0 {{end}} : pipeline 값이 empty면 T0 수행
Ø {{if pipeline}} T1 {{else if pipeline}} T0 {{end}}
Ø {{range pipeline}} T1 {{end}}
pipeline 은 array, slice, map, channel 중 하나, pipeline 길이가 0이 아니면 수행
dot 으로 지정된 pipeline 의 값으로 수행
Ø {{range pipeline}} T1 {{else}} T0 {{end}}
dot 으로 지정된 pipeline 의 값으로 수행
Ø {{template "name"}} : "name" template 을 nil data 로 전달하여 수행
Ø {{template "name" pipeline}}
"name" template 을 dot 으로 지정된 pipeline 의 값을 전달하여 수행
Ø {{block "name" pipeline}} T1 {{end}}
block 은 template을 간단히 정의 : {{define "name""}} T1 {{end}}
그리고 나서 template 을 dot 지정 값으로 수행 : {{template "name" .}}
Template Functions
$ vi	mychart/templates/configmap.yaml
apiVersion:	v1
kind:	ConfigMap
metadata:
name:	{{	.Release.Name	}}-configmap
data:
myvalue:	"Hello	World"
drink:	{{	quote .Values.favorite.drink	}}
food:	{{	quote .Values.favorite.food	}}
$ helm	upgrade	needled-rottweiler	./mychart
Ø {{ functionName arg1 arg2 … }} 와 같은 방식으로 호출 : String 에 Quote 추가
Template Functions
- date	FORMAT	TIME
- now
Ø Date Functions
- trunc
- trim, trimAll
- upper,	lower,	nospace
- repeat,	substr
- contains
- quote
- indent
- replace
- toString
Ø String Functions
- join
- split	:	`{{$v	:=	"foo/bar"	|	split	"/"}}{{$v._0}}`	(Prints	`foo`)
Ø String Slice Functions
- default	:	trim	"			"	|	default	"empty"
- env	:	environment	variable
Ø Defaults & OS
Template Functions
- b64enc:	Base	64	encode	a	string.
- b64dec:	Base	64	decode	a	string.
Ø Encoding
- tuple
- list
- dict
Ø Data Structures
- first,	last
- rest		:		첫번째 아이템 제외한 나머지 리턴
- initial	:	마지막 아이템 제외한 나머지 리턴
- append	:	마지막에 추가
- prepend:	처음에 추가
- reverse
- uniq
- has
ex)	'{{	list	1	2	3	|	reverse	|	first	}}'
Ø List Functions
Template Functions
- add1		:	1만 더하기
- add
- sub
- div
- mod
- mul
- max
- min
Ø Math Functions
- set
- unset
- hasKey
- keys
- pick	:	주어진 key에 대한 새로운 dick	이 리턴
- omit : 주어진 key만 생략하고 나머지 dick	을 리턴
ex)	'{{set	$dick	$key,	$value	}}'
Ø Dick Functions
Controlling Whitespace
apiVersion:	v1
kind:	ConfigMap
metadata:
name:	{{	.Release.Name	}}-configmap
data:
myvalue:	"Hello	World"
drink:	{{	.Values.favorite.drink	|	default	"tea"	|	quote	}}
food:	{{	.Values.favorite.food	|	upper	|	quote	}}
{{- if	eq	.Values.favorite.drink	"coffee"}}
mug:	true
{{- end}}
apiVersion:	v1
kind:	ConfigMap
metadata:
name:	eyewitness-elk-configmap
data:
myvalue:	"Hello	World"
drink:	"coffee"
food:	"PIZZA"
mug:	true
Ø {{- : 좌측의 whitespace 를 없앰
Ø -}} : 우측의 whitespace 를 없앰, Newline 도 whitespace 임.
with 로 scope 변경
{{	with PIPELINE	}}
#	restricted	scope
{{	end }}
apiVersion:	v1
kind:	ConfigMap
metadata:
name:	{{	.Release.Name	}}-configmap
data:
myvalue:	"Hello	World"
{{- with .Values.favorite }}
drink:	{{	.drink |	default	"tea"	|	quote	}}
food:	{{	.food |	upper	|	quote	}}
{{- end }}
Ø . 은 current scope 으로 .Values values.yaml 의 Values 객체를 나타냄
Ø {{ with }} {{ end }} 로 scope 을 변경할 수 있음
Variables
{{- with	.Values.favorite	}}
drink:	{{	.drink	|	default	"tea"	|	quote	}}
food:	{{	.food	|	upper	|	quote	}}
release:	{{	.Release.Name	}}
{{- end	}}
#	.Release.Name 은 with	scope	안에 있어서 문제가 발생,	이 때 변수를 활용
apiVersion:	v1
kind:	ConfigMap
metadata:
name:	{{	.Release.Name	}}-configmap
data:
myvalue:	"Hello	World"
{{- $relname	:=	.Release.Name	-}}
{{- with	.Values.favorite	}}
drink:	{{	.drink	|	default	"tea"	|	quote	}}
food:	{{	.food	|	upper	|	quote	}}
release:	{{	$relname }}
{{- end	}}
Ø variables 를 with 에서 사용
Variables
{{- range .Values.tlsSecrets	}}
apiVersion:	v1
kind:	Secret
metadata:
name:	{{	.name	}}
labels:
#	.	을 사용하면 안되고 `$`	를 사용해야 함
app:	{{	template	"fullname"	$ }}
#	.Chart.Name	은 range	때문에 scope	의 영향을 받으므로 $.Chart.Name	를 사용
chart:	"{{	$.Chart.Name	}}-{{	$.Chart.Version	}}"
release:	"{{	$.Release.Name	}}"
heritage:	"{{	$.Release.Service	}}"
type:	kubernetes.io/tls
data:
tls.crt:	{{	.certificate	}}
tls.key:	{{	.key	}}
---
{{- end	}}
Ø $ 는 global 변수로 root context 를 나타낸다.
Mariadb chart 배포
$	helm	search	stable
$	helm	fetch	mariadb
$	tree	mariadb
mariadb
├── Chart.yaml
├── README.md
├── templates
│ ├── configmap.yaml
│ ├── deployment.yaml
│ ├── _helpers.tpl
│ ├── NOTES.txt
│ ├── pvc.yaml
│ ├── secrets.yaml
│ ├── svc.yaml
│ ├── test-runner.yaml
│ └── tests.yaml
└── values.yaml
Mariadb chart 배포
$	helm	install	./mariadb	--name	mariadb-default
Q&A

Weitere ähnliche Inhalte

Was ist angesagt?

Kubernetes
KubernetesKubernetes
Kuberneteserialc_w
 
OpenStack DevStack Install - 2부 (Multi-nodes)
OpenStack DevStack Install - 2부 (Multi-nodes)OpenStack DevStack Install - 2부 (Multi-nodes)
OpenStack DevStack Install - 2부 (Multi-nodes)Ian Choi
 
Hands-On Introduction to Kubernetes at LISA17
Hands-On Introduction to Kubernetes at LISA17Hands-On Introduction to Kubernetes at LISA17
Hands-On Introduction to Kubernetes at LISA17Ryan Jarvinen
 
Kubernetes internals (Kubernetes 해부하기)
Kubernetes internals (Kubernetes 해부하기)Kubernetes internals (Kubernetes 해부하기)
Kubernetes internals (Kubernetes 해부하기)DongHyeon Kim
 
OpenvSwitch Deep Dive
OpenvSwitch Deep DiveOpenvSwitch Deep Dive
OpenvSwitch Deep Diverajdeep
 
[오픈소스컨설팅]Ansible overview
[오픈소스컨설팅]Ansible overview[오픈소스컨설팅]Ansible overview
[오픈소스컨설팅]Ansible overviewOpen Source Consulting
 
VMware が考えるコンテナと Kubernetes の世界
VMware が考えるコンテナと Kubernetes の世界VMware が考えるコンテナと Kubernetes の世界
VMware が考えるコンテナと Kubernetes の世界Yuichi Tamagawa
 
Introduction to ansible
Introduction to ansibleIntroduction to ansible
Introduction to ansibleOmid Vahdaty
 
Evolution of containers to kubernetes
Evolution of containers to kubernetesEvolution of containers to kubernetes
Evolution of containers to kubernetesKrishna-Kumar
 
Virtualization Architecture & KVM
Virtualization Architecture & KVMVirtualization Architecture & KVM
Virtualization Architecture & KVMPradeep Kumar
 
Chef vs Puppet vs Ansible vs SaltStack | Configuration Management Tools Compa...
Chef vs Puppet vs Ansible vs SaltStack | Configuration Management Tools Compa...Chef vs Puppet vs Ansible vs SaltStack | Configuration Management Tools Compa...
Chef vs Puppet vs Ansible vs SaltStack | Configuration Management Tools Compa...Edureka!
 
Docker introduction
Docker introductionDocker introduction
Docker introductionPhuc Nguyen
 
OverlayFS as a Docker Storage Driver
OverlayFS as a Docker Storage DriverOverlayFS as a Docker Storage Driver
OverlayFS as a Docker Storage DriverTomoya Akase
 
Architecture Overview: Kubernetes with Red Hat Enterprise Linux 7.1
Architecture Overview: Kubernetes with Red Hat Enterprise Linux 7.1Architecture Overview: Kubernetes with Red Hat Enterprise Linux 7.1
Architecture Overview: Kubernetes with Red Hat Enterprise Linux 7.1Etsuji Nakai
 
DevOps with Ansible
DevOps with AnsibleDevOps with Ansible
DevOps with AnsibleSwapnil Jain
 

Was ist angesagt? (20)

Kubernetes
KubernetesKubernetes
Kubernetes
 
OpenStack DevStack Install - 2부 (Multi-nodes)
OpenStack DevStack Install - 2부 (Multi-nodes)OpenStack DevStack Install - 2부 (Multi-nodes)
OpenStack DevStack Install - 2부 (Multi-nodes)
 
Hands-On Introduction to Kubernetes at LISA17
Hands-On Introduction to Kubernetes at LISA17Hands-On Introduction to Kubernetes at LISA17
Hands-On Introduction to Kubernetes at LISA17
 
Kubernetes internals (Kubernetes 해부하기)
Kubernetes internals (Kubernetes 해부하기)Kubernetes internals (Kubernetes 해부하기)
Kubernetes internals (Kubernetes 해부하기)
 
OpenvSwitch Deep Dive
OpenvSwitch Deep DiveOpenvSwitch Deep Dive
OpenvSwitch Deep Dive
 
[오픈소스컨설팅]Ansible overview
[오픈소스컨설팅]Ansible overview[오픈소스컨설팅]Ansible overview
[오픈소스컨설팅]Ansible overview
 
VMware が考えるコンテナと Kubernetes の世界
VMware が考えるコンテナと Kubernetes の世界VMware が考えるコンテナと Kubernetes の世界
VMware が考えるコンテナと Kubernetes の世界
 
Introduction to ansible
Introduction to ansibleIntroduction to ansible
Introduction to ansible
 
Evolution of containers to kubernetes
Evolution of containers to kubernetesEvolution of containers to kubernetes
Evolution of containers to kubernetes
 
Virtualization Architecture & KVM
Virtualization Architecture & KVMVirtualization Architecture & KVM
Virtualization Architecture & KVM
 
Helm intro
Helm introHelm intro
Helm intro
 
Chef vs Puppet vs Ansible vs SaltStack | Configuration Management Tools Compa...
Chef vs Puppet vs Ansible vs SaltStack | Configuration Management Tools Compa...Chef vs Puppet vs Ansible vs SaltStack | Configuration Management Tools Compa...
Chef vs Puppet vs Ansible vs SaltStack | Configuration Management Tools Compa...
 
Terraform
TerraformTerraform
Terraform
 
Docker introduction
Docker introductionDocker introduction
Docker introduction
 
ansible why ?
ansible why ?ansible why ?
ansible why ?
 
OverlayFS as a Docker Storage Driver
OverlayFS as a Docker Storage DriverOverlayFS as a Docker Storage Driver
OverlayFS as a Docker Storage Driver
 
Architecture Overview: Kubernetes with Red Hat Enterprise Linux 7.1
Architecture Overview: Kubernetes with Red Hat Enterprise Linux 7.1Architecture Overview: Kubernetes with Red Hat Enterprise Linux 7.1
Architecture Overview: Kubernetes with Red Hat Enterprise Linux 7.1
 
DevOps with Ansible
DevOps with AnsibleDevOps with Ansible
DevOps with Ansible
 
Ansible - Introduction
Ansible - IntroductionAnsible - Introduction
Ansible - Introduction
 
Prometheus Storage
Prometheus StoragePrometheus Storage
Prometheus Storage
 

Ähnlich wie Kubernetes & helm 활용

2017 k8s and OpenStack-Helm
2017 k8s and OpenStack-Helm2017 k8s and OpenStack-Helm
2017 k8s and OpenStack-HelmSK Telecom
 
[오픈소스컨설팅]쿠버네티스를 활용한 개발환경 구축
[오픈소스컨설팅]쿠버네티스를 활용한 개발환경 구축[오픈소스컨설팅]쿠버네티스를 활용한 개발환경 구축
[오픈소스컨설팅]쿠버네티스를 활용한 개발환경 구축Ji-Woong Choi
 
02.실전! 시스템 관리자를 위한 Ansible
02.실전! 시스템 관리자를 위한 Ansible02.실전! 시스템 관리자를 위한 Ansible
02.실전! 시스템 관리자를 위한 AnsibleOpennaru, inc.
 
Ch7,8. Configmaps, Secrets and API
Ch7,8. Configmaps, Secrets and APICh7,8. Configmaps, Secrets and API
Ch7,8. Configmaps, Secrets and APIHongmin Park
 
ECS+Locust로 부하 테스트 진행하기
ECS+Locust로 부하 테스트 진행하기ECS+Locust로 부하 테스트 진행하기
ECS+Locust로 부하 테스트 진행하기Yungon Park
 
[IoT] MAKE with Open H/W + Node.JS - 3rd
[IoT] MAKE with Open H/W + Node.JS - 3rd[IoT] MAKE with Open H/W + Node.JS - 3rd
[IoT] MAKE with Open H/W + Node.JS - 3rdPark Jonggun
 
XECon2015 :: [1-5] 김훈민 - 서버 운영자가 꼭 알아야 할 Docker
XECon2015 :: [1-5] 김훈민 - 서버 운영자가 꼭 알아야 할 DockerXECon2015 :: [1-5] 김훈민 - 서버 운영자가 꼭 알아야 할 Docker
XECon2015 :: [1-5] 김훈민 - 서버 운영자가 꼭 알아야 할 DockerXpressEngine
 
AWS SAM으로 서버리스 아키텍쳐 운영하기 - 이재면(마이뮤직테이스트) :: AWS Community Day 2020
AWS SAM으로 서버리스 아키텍쳐 운영하기 - 이재면(마이뮤직테이스트) :: AWS Community Day 2020 AWS SAM으로 서버리스 아키텍쳐 운영하기 - 이재면(마이뮤직테이스트) :: AWS Community Day 2020
AWS SAM으로 서버리스 아키텍쳐 운영하기 - 이재면(마이뮤직테이스트) :: AWS Community Day 2020 AWSKRUG - AWS한국사용자모임
 
Kubernetes on GCP
Kubernetes on GCPKubernetes on GCP
Kubernetes on GCPDaegeun Kim
 
Nodejs, PhantomJS, casperJs, YSlow, expressjs
Nodejs, PhantomJS, casperJs, YSlow, expressjsNodejs, PhantomJS, casperJs, YSlow, expressjs
Nodejs, PhantomJS, casperJs, YSlow, expressjs기동 이
 
Ansible를 통한 컨테이너 환경 자동화
Ansible를 통한 컨테이너 환경 자동화Ansible를 통한 컨테이너 환경 자동화
Ansible를 통한 컨테이너 환경 자동화Opennaru, inc.
 
2.apache spark 실습
2.apache spark 실습2.apache spark 실습
2.apache spark 실습동현 강
 
7가지 동시성 모델 람다아키텍처
7가지 동시성 모델  람다아키텍처7가지 동시성 모델  람다아키텍처
7가지 동시성 모델 람다아키텍처Sunggon Song
 
Terraform을 이용한 Infrastructure as Code 실전 구성하기 :: 변정훈::AWS Summit Seoul 2018
 Terraform을 이용한 Infrastructure as Code 실전 구성하기 :: 변정훈::AWS Summit Seoul 2018 Terraform을 이용한 Infrastructure as Code 실전 구성하기 :: 변정훈::AWS Summit Seoul 2018
Terraform을 이용한 Infrastructure as Code 실전 구성하기 :: 변정훈::AWS Summit Seoul 2018Amazon Web Services Korea
 
Terraform을 이용한 Infrastructure as Code 실전 구성하기
Terraform을 이용한 Infrastructure as Code 실전 구성하기Terraform을 이용한 Infrastructure as Code 실전 구성하기
Terraform을 이용한 Infrastructure as Code 실전 구성하기JeongHun Byeon
 

Ähnlich wie Kubernetes & helm 활용 (20)

2017 k8s and OpenStack-Helm
2017 k8s and OpenStack-Helm2017 k8s and OpenStack-Helm
2017 k8s and OpenStack-Helm
 
03.Ansible 소개
03.Ansible 소개03.Ansible 소개
03.Ansible 소개
 
[오픈소스컨설팅]쿠버네티스를 활용한 개발환경 구축
[오픈소스컨설팅]쿠버네티스를 활용한 개발환경 구축[오픈소스컨설팅]쿠버네티스를 활용한 개발환경 구축
[오픈소스컨설팅]쿠버네티스를 활용한 개발환경 구축
 
02.실전! 시스템 관리자를 위한 Ansible
02.실전! 시스템 관리자를 위한 Ansible02.실전! 시스템 관리자를 위한 Ansible
02.실전! 시스템 관리자를 위한 Ansible
 
One-day-codelab
One-day-codelabOne-day-codelab
One-day-codelab
 
Apache avro
Apache avroApache avro
Apache avro
 
Ch7,8. Configmaps, Secrets and API
Ch7,8. Configmaps, Secrets and APICh7,8. Configmaps, Secrets and API
Ch7,8. Configmaps, Secrets and API
 
ECS+Locust로 부하 테스트 진행하기
ECS+Locust로 부하 테스트 진행하기ECS+Locust로 부하 테스트 진행하기
ECS+Locust로 부하 테스트 진행하기
 
[IoT] MAKE with Open H/W + Node.JS - 3rd
[IoT] MAKE with Open H/W + Node.JS - 3rd[IoT] MAKE with Open H/W + Node.JS - 3rd
[IoT] MAKE with Open H/W + Node.JS - 3rd
 
XECon2015 :: [1-5] 김훈민 - 서버 운영자가 꼭 알아야 할 Docker
XECon2015 :: [1-5] 김훈민 - 서버 운영자가 꼭 알아야 할 DockerXECon2015 :: [1-5] 김훈민 - 서버 운영자가 꼭 알아야 할 Docker
XECon2015 :: [1-5] 김훈민 - 서버 운영자가 꼭 알아야 할 Docker
 
AWS SAM으로 서버리스 아키텍쳐 운영하기 - 이재면(마이뮤직테이스트) :: AWS Community Day 2020
AWS SAM으로 서버리스 아키텍쳐 운영하기 - 이재면(마이뮤직테이스트) :: AWS Community Day 2020 AWS SAM으로 서버리스 아키텍쳐 운영하기 - 이재면(마이뮤직테이스트) :: AWS Community Day 2020
AWS SAM으로 서버리스 아키텍쳐 운영하기 - 이재면(마이뮤직테이스트) :: AWS Community Day 2020
 
Warp
WarpWarp
Warp
 
Kubernetes on GCP
Kubernetes on GCPKubernetes on GCP
Kubernetes on GCP
 
Nodejs, PhantomJS, casperJs, YSlow, expressjs
Nodejs, PhantomJS, casperJs, YSlow, expressjsNodejs, PhantomJS, casperJs, YSlow, expressjs
Nodejs, PhantomJS, casperJs, YSlow, expressjs
 
Ansible를 통한 컨테이너 환경 자동화
Ansible를 통한 컨테이너 환경 자동화Ansible를 통한 컨테이너 환경 자동화
Ansible를 통한 컨테이너 환경 자동화
 
테스트
테스트테스트
테스트
 
2.apache spark 실습
2.apache spark 실습2.apache spark 실습
2.apache spark 실습
 
7가지 동시성 모델 람다아키텍처
7가지 동시성 모델  람다아키텍처7가지 동시성 모델  람다아키텍처
7가지 동시성 모델 람다아키텍처
 
Terraform을 이용한 Infrastructure as Code 실전 구성하기 :: 변정훈::AWS Summit Seoul 2018
 Terraform을 이용한 Infrastructure as Code 실전 구성하기 :: 변정훈::AWS Summit Seoul 2018 Terraform을 이용한 Infrastructure as Code 실전 구성하기 :: 변정훈::AWS Summit Seoul 2018
Terraform을 이용한 Infrastructure as Code 실전 구성하기 :: 변정훈::AWS Summit Seoul 2018
 
Terraform을 이용한 Infrastructure as Code 실전 구성하기
Terraform을 이용한 Infrastructure as Code 실전 구성하기Terraform을 이용한 Infrastructure as Code 실전 구성하기
Terraform을 이용한 Infrastructure as Code 실전 구성하기
 

Kubernetes & helm 활용

  • 2. 2 Kubernetes Resources 4 [ Pod ] • 컨테이너를 담고 있는 그릇 (여러개의 컨테이너가 포함될 수 있음) • 같은 Pods 안에서의 여러 컨테이너가 같은 네트워크 네임스페이스와 ip 를 가짐 (Apache -> (localhost, port) -> Tomcat) • 같은 Pods 안에서의 여러 컨테이너가 같은 볼륨을 볼 수 있음 [ ReplicaSet ] • Pod 개수를 관리 [ Deployment ] • Pod 와 Replica Set 을 통합하여 배포할 수 있는 단위 • 배포 히스토리를 버전별로 관리 [ Service ] • Route to pod (using labels) – 내부 IP로 Pod 에 대한 Load Balancing (기본기능) • 외부에서 접근할려면 아래 두 타입을 활용하여 가능 • 타입 : Load balancer (GCE), NodePort (iptables) [ ConfigMap and Secret ] • ConfigMap : Application 의 Configuration, 혹은 shell script • Secret : 보안 값
  • 3. 3 Pod 3 • 컨테이너 배포 단위로 컨테이너를 담고 있는 그릇 • 여러 개의 컨테이너가 포함될 수 있음 • 하나의 Pod 안에서의 여러 컨테이너는 같은 docker ip 를 가짐 • pause 컨테이너가 하나씩 생김 • Pod 내부에서 컨테이너간 통신은 localhost & 포트로 통신 • Docker Networking 의 Mapped Container Mode docker run -d --name pause pause_image docker run -d --name web -net=container:pause web_image • 하나의 Pods 안에서의 여러 컨테이너는 같은 볼륨을 볼 수 있다.
  • 4. 4 ReplicaSet 44 • Pod 의 개수를 지정해서 실행 • 실행 중인 Pod 의 수를 항상 보장 • Pod 를 명령어로 삭제해도 ReplicaSet 에 의해 자동 복구됨 • Horizontal Pod Autoscaler 가 autoscale 을 할 때 ReplicaSet 활용 • ReplicaSet = Pod + replicas 수 (Pod 개수) apiVersion: autoscaling/v2beta1 kind: HorizontalPodAutoscaler metadata: name: frontend-scaler spec: scaleTargetRef: apiVersion: apps/v1beta1 kind: Deployment name: frontend minReplicas: 3 maxReplicas: 10 metrics: - type: Resource resource: name: cpu targetAverageUtilization: 50
  • 5. Deployment 7 • Deployment = ReplicaSet + History (Revision) • Pod 배포에 대한 버전 관리가 가능 apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment namespace: default spec: replicas: 3 template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:1.7.9 ports: - containerPort: 80 $ kubectl create -f nginx.yaml $ kubectl rollout history deployment/nginx- deployment $ kubectl rollout history deployment/nginx- deployment --revision=2 $ kubectl rollout undo deployment/nginx- deployment --to-revision=2
  • 6. Service 8 • Type: ClusterIP(default), LoadBalancer, NodePort, ExternalName • Pod 를 대표하는 DNS 이름 • ClusterIP 가 할당됨 (Virtual IP) • kube-proxy 가 iptables 에 Cluster IP 세팅 • Simple Load Balance (default : Round Robin) • selector 를 지정하면 Endpoint 가 생김 Service Pod B-1 Pod B-2 Pod A-1 serivce명 & port Pod IP & port (Endpoint) apiVersion: v1 kind: Service metadata: name: frontend labels: app: guestbook tier: frontend spec: type: NodePort ports: - port: 80 nodePort: 31000 selector: app: guestbook tier: frontend
  • 7. 7 What is Helm? The package manager for Kubernetes Helm helps you manage Kubernetes applications - Helm Charts helps you define, install, and upgrade even the most complex Kubernetes application. Charts are easy to create, version, share, and publish - so start using Helm and stop the copy-and-paste madness.
  • 10. Helm Architecture Helm Client Kubernetes Cluster Tiller Server Kube-api ① Authentication Chart ③ Installing chart ② Request to install (gRPC) Manifest file
  • 11. Helm Architecture Helm Client • a command-line client for end users. • Managing repositories • Interacting with the Tiller server • Sending charts to be installed • Asking for information about releases • Requesting upgrading or uninstalling of existing releases Tiller Server • an in-cluster server that interacts with the Helm client, and interfaces with the Kubernetes API server. • Listening for incoming requests from the Helm client • Combining a chart and configuration to build a release • Installing charts into Kubernetes, and then tracking the subsequent release • Upgrading and uninstalling charts by interacting with Kubernetes
  • 12. Simple chart 생성 $ helm create mychart mychart/ ├── charts/ ├── Chart.yaml ├── templates/ │ ├── deployment.yaml │ ├── _helpers.tpl │ ├── ingress.yaml │ ├── NOTES.txt │ └── service.yaml └── values.yaml helm install 시에 디스플레이 되는 문장 kubernetes 기본 manifest 파일 kubernetes service manifest 파일 template helper, utililty function 처럼 동작 tiller 가 templates rendering engine 을 통해 generation chart version 등 chart 에 대한 설명을 담고 있음 subcharts 라 부르는 다른 chart를 포함할 수 있는 디렉토리 kubernetes ingress manifest 파일 chart에 대한 기본 값을 저장, 변수처럼 활용 helm install 이나 helm upgrade 시에 override 가능
  • 13. Template directive $ vi mychart/templates/configmap.yaml apiVersion: v1 kind: ConfigMap metadata: name: {{ .Release.Name }}-configmap data: myvalue: "Hello World" - Template 지시자는 {{ }} 로 표시 - Value 가 template 안에서 치환되며 dot( . ) 으로 시작하여 namespace 를 넣을 수 있다. - 맨처음의 dot 은 최상의 네임스페이스를 의미하며 Release 는 내장 (built-in) 객체로서 Name 객체를 가지고 있다. $ helm install ./mychart $ kubectl get configmap NAME DATA AGE iced-bear-configmap 1 19s $ helm get manifest iced-bear $ helm delete iced-bear
  • 14. Build-in Objects Release {{ .Release.Name }}, {{ .Release.Namespace }}, {{ .Release.Service }} {{ .Release.Revision }}, {{ .Release.IsUpgrade }}, {{ .Release.IsInstall }} Values values.yaml 파일에 정의된 값 (직접 수정하거나 Override 할 수 있는 값) {{ .Values.xxx }} Chart {{ .Chart.Name }}, {{ .Chart.Version }} Template {{ .Template.Name }} : 현재 template 파일명 {{ .Template.BasePath }} : template 디렉토리 경로 Files, Capabilities
  • 15. Values File $ vi mychart/values.yaml favoriteDrink: coffee $ vi mychart/templates/configmap.yaml apiVersion: v1 kind: ConfigMap metadata: name: {{ .Release.Name }}-configmap data: myvalue: "Hello World" drink: {{ .Values.favoriteDrink }} $ helm install ./mychart NAME: needled-rottweiler LAST DEPLOYED: Fri Feb 23 04:57:15 2018 NAMESPACE: default STATUS: DEPLOYED RESOURCES: ==> v1/ConfigMap NAME DATA AGE needled-rottweiler-configmap 2 0s Ø values.yaml 파일 위치는 chart 최상위 디렉토리에 위치 (e.g. ./mychart/values.yaml) Ø helm install 혹은 helm upgrade 시에 -f 로 override 가능 Ø --set key=value 로 value override 가능
  • 16. Template "{{23 -}} < {{- 45}}" 는 "23<45" 와 같이 공백없이 출력 Ø "{{-" 은 text 앞의 공백을 없앤다. Ø "-}}" 은 text 뒤의 공백을 없앤다. Ø {{/* a comment */}} : 주석 처리 Ø {{pipeline}} : 값 print Ø {{if pipeline}} T1 {{end}} pipeline 값이 empty가 아니면 T1 수행 empty 정의 : false, 0, nil 그리고 array, slice, map, string 의 길이가 0 Ø {{if pipeline}} T1 {{else}} T0 {{end}} : pipeline 값이 empty면 T0 수행 Ø {{if pipeline}} T1 {{else if pipeline}} T0 {{end}} Ø {{range pipeline}} T1 {{end}} pipeline 은 array, slice, map, channel 중 하나, pipeline 길이가 0이 아니면 수행 dot 으로 지정된 pipeline 의 값으로 수행 Ø {{range pipeline}} T1 {{else}} T0 {{end}} dot 으로 지정된 pipeline 의 값으로 수행 Ø {{template "name"}} : "name" template 을 nil data 로 전달하여 수행 Ø {{template "name" pipeline}} "name" template 을 dot 으로 지정된 pipeline 의 값을 전달하여 수행 Ø {{block "name" pipeline}} T1 {{end}} block 은 template을 간단히 정의 : {{define "name""}} T1 {{end}} 그리고 나서 template 을 dot 지정 값으로 수행 : {{template "name" .}}
  • 17. Template Functions $ vi mychart/templates/configmap.yaml apiVersion: v1 kind: ConfigMap metadata: name: {{ .Release.Name }}-configmap data: myvalue: "Hello World" drink: {{ quote .Values.favorite.drink }} food: {{ quote .Values.favorite.food }} $ helm upgrade needled-rottweiler ./mychart Ø {{ functionName arg1 arg2 … }} 와 같은 방식으로 호출 : String 에 Quote 추가
  • 18. Template Functions - date FORMAT TIME - now Ø Date Functions - trunc - trim, trimAll - upper, lower, nospace - repeat, substr - contains - quote - indent - replace - toString Ø String Functions - join - split : `{{$v := "foo/bar" | split "/"}}{{$v._0}}` (Prints `foo`) Ø String Slice Functions - default : trim " " | default "empty" - env : environment variable Ø Defaults & OS
  • 19. Template Functions - b64enc: Base 64 encode a string. - b64dec: Base 64 decode a string. Ø Encoding - tuple - list - dict Ø Data Structures - first, last - rest : 첫번째 아이템 제외한 나머지 리턴 - initial : 마지막 아이템 제외한 나머지 리턴 - append : 마지막에 추가 - prepend: 처음에 추가 - reverse - uniq - has ex) '{{ list 1 2 3 | reverse | first }}' Ø List Functions
  • 20. Template Functions - add1 : 1만 더하기 - add - sub - div - mod - mul - max - min Ø Math Functions - set - unset - hasKey - keys - pick : 주어진 key에 대한 새로운 dick 이 리턴 - omit : 주어진 key만 생략하고 나머지 dick 을 리턴 ex) '{{set $dick $key, $value }}' Ø Dick Functions
  • 21. Controlling Whitespace apiVersion: v1 kind: ConfigMap metadata: name: {{ .Release.Name }}-configmap data: myvalue: "Hello World" drink: {{ .Values.favorite.drink | default "tea" | quote }} food: {{ .Values.favorite.food | upper | quote }} {{- if eq .Values.favorite.drink "coffee"}} mug: true {{- end}} apiVersion: v1 kind: ConfigMap metadata: name: eyewitness-elk-configmap data: myvalue: "Hello World" drink: "coffee" food: "PIZZA" mug: true Ø {{- : 좌측의 whitespace 를 없앰 Ø -}} : 우측의 whitespace 를 없앰, Newline 도 whitespace 임.
  • 22. with 로 scope 변경 {{ with PIPELINE }} # restricted scope {{ end }} apiVersion: v1 kind: ConfigMap metadata: name: {{ .Release.Name }}-configmap data: myvalue: "Hello World" {{- with .Values.favorite }} drink: {{ .drink | default "tea" | quote }} food: {{ .food | upper | quote }} {{- end }} Ø . 은 current scope 으로 .Values values.yaml 의 Values 객체를 나타냄 Ø {{ with }} {{ end }} 로 scope 을 변경할 수 있음
  • 23. Variables {{- with .Values.favorite }} drink: {{ .drink | default "tea" | quote }} food: {{ .food | upper | quote }} release: {{ .Release.Name }} {{- end }} # .Release.Name 은 with scope 안에 있어서 문제가 발생, 이 때 변수를 활용 apiVersion: v1 kind: ConfigMap metadata: name: {{ .Release.Name }}-configmap data: myvalue: "Hello World" {{- $relname := .Release.Name -}} {{- with .Values.favorite }} drink: {{ .drink | default "tea" | quote }} food: {{ .food | upper | quote }} release: {{ $relname }} {{- end }} Ø variables 를 with 에서 사용
  • 24. Variables {{- range .Values.tlsSecrets }} apiVersion: v1 kind: Secret metadata: name: {{ .name }} labels: # . 을 사용하면 안되고 `$` 를 사용해야 함 app: {{ template "fullname" $ }} # .Chart.Name 은 range 때문에 scope 의 영향을 받으므로 $.Chart.Name 를 사용 chart: "{{ $.Chart.Name }}-{{ $.Chart.Version }}" release: "{{ $.Release.Name }}" heritage: "{{ $.Release.Service }}" type: kubernetes.io/tls data: tls.crt: {{ .certificate }} tls.key: {{ .key }} --- {{- end }} Ø $ 는 global 변수로 root context 를 나타낸다.
  • 25. Mariadb chart 배포 $ helm search stable $ helm fetch mariadb $ tree mariadb mariadb ├── Chart.yaml ├── README.md ├── templates │ ├── configmap.yaml │ ├── deployment.yaml │ ├── _helpers.tpl │ ├── NOTES.txt │ ├── pvc.yaml │ ├── secrets.yaml │ ├── svc.yaml │ ├── test-runner.yaml │ └── tests.yaml └── values.yaml
  • 27. Q&A