Kubernetes のパッケージマネジャー helm の導入と使い方
概要
Deis が開発した Kubernetes のパッケージマネージメントツール Helm を使ってみる
helm の特徴は以下の通り
- kubernetes のマニフェストファイル群(RC, Service, Pod)をパッケージ化したもの chart と呼んでいる
- パッケージをカスタマイズして kubernetes 上にアプリを構築できる
- ReplicationController, Service を一括でデプロイしてくれる
helm インストール
以下コマンドで helm バイナリ ができるので、適当に PATH を通す
$ curl -s https://get.helm.sh | bash
初期設定
以下コマンド実行で $HOME/.helm にレポジトリ設定や charts (マニフェスト)が保存される
$ helm update
デフォルトで登録されるレポジトリは以下
https://github.com/helm/charts
ディレクトリの中身
/home/*****/.helm/
|
|--config.yaml #レポジトリ設定
|
|--cache
|
|--charts #helm update で取得した kubernetes マニフェスト
| |--alpine
| |--Chart.yaml
| |--manifests
| |--alpine-pod.yaml
|
| |--cassandra
| |--Chart.yaml
| |--manifests
...snip...
|
|--- workspace #作業用ディレクトリ(helm fetch でコピーされる)
charts 一覧取得
$ helm search
2016/01/15時点のリスト
alpine - Simple pod running Alpine Linux.
cassandra - The Apache Cassandra Project.
docker-registry - The Docker toolset to pack, ship, store, and deliver content.
elasticsearch - Elasticsearch Restful Search Engine
example-nginx - An example nginx + git-sync application
example-todo - Example Todo application backed by Redis
jenkins - The leading open-source continuous integration server.
memcached - A simple Memcached cluster
mysql - Chart running MySQL.
nginx - Nginx http service
nginx-alpine - Nginx http service
owncloud - a self-hosted file sync and share server.
postgresql - The world's most advanced open source database.
proxy-2-service - Proxy a pod port or host port to a kubernetes Service
rabbitmq - Chart running RabbitMQ.
redis-cluster - Highly available Redis cluster with multiple sentinels and standbys.
redis-standalone - Standalone Redis Master
redmine - A flexible project management web application.
riak - A distributed NoSQL database.
selenium - Selenium is a suite of tools to automate web browsers across many platforms.
ubuntu-debootstrap - Simple pod running minimal Ubuntu
kubernetes にデプロイ
リストにあった redmine を構築してみる
事前に kubectl を使えるようにしておく必要がある
$ helm install redmine
---> Running `kubectl create -f` ...
service "redmine" created
replicationcontroller "redmine" created
---> Done
========================================
# Redmine
Redmine is a flexible project management web application written using Ruby on Rails framework.
========================================
確認
$ kubectl get pod
NAME READY STATUS RESTARTS AGE
redmine-zdetd 1/1 Running 0 1m
$ kubectl get svc
NAME CLUSTER_IP EXTERNAL_IP PORT(S) SELECTOR AGE
redmine 10.55.241.60 <none> 80/TCP app=redmine 1m
削除
$ helm uninstall redmine
Service/redmine
ReplicationController/redmine
Uninstall the listed objects? (y/N) y
---> Running `kubectl delete` ...
---> service "redmine" deleted
---> replicationcontroller "redmine" deleted
---> Done
自前のレポジトリを使って helm で Wordpress を構築
事前準備
デフォルトのレポジトリを削除
$ helm repo rm charts
レポジトリを登録
$ helm repo add charts https://github.com/quickguard/charts
---> Cloning into '/home/******/.helm/cache/charts'...
---> Hooray! Successfully added the repo.
確認
$ helm search wordpress
wordpress - The WordPress rich content management system can utilize plugins, widgets, and themes.
charts を編集
レポジトリから取得した charts を作業用ディレクトリにコピー
$ helm fetch wordpress
---> Fetched chart into workspace /home/******/.helm/workspace/charts/wordpress
---> Done
charts 編集(事前に $EDITOR を export しておく)
$ helm edit wordpress
データ永続用の pd を作成しておく
$ gcloud compute disks create --size=10GB --zone=asia-east1-b mysql-data-disk
$ gcloud compute disks create --size=10GB --zone=asia-east1-b wordpress-data-disk
kubernetes にデプロイ
$ helm install wordpress
---> Running `kubectl create -f` ...
service "mysql" created
service "wpfrontend" created
replicationcontroller "mysql" created
replicationcontroller "wordpress" created
---> Done
========================================
# Wordpress
Redmine is a free and open source, web-based project management and issue tracking tool. It allows users to manage multiple projects and associated subprojects. It features per project wikis and forums, time tracking, and flexible role based access control. It includes a calendar and Gantt charts to aid visual representation of projects and their deadlines. Redmine integrates with various version control systems and includes a repository browser and diff viewer.
========================================
確認
$ kubectl get rc
CONTROLLER CONTAINER(S) IMAGE(S) SELECTOR REPLICAS AGE
mysql mysql mysql:5.6 name=mysql 1 5m
wordpress wordpress wordpress name=wordpress 1 5m
$ kubectl get svc
NAME CLUSTER_IP EXTERNAL_IP PORT(S) SELECTOR AGE
kubernetes 10.55.240.1 <none> 443/TCP <none> 5h
mysql 10.55.245.221 <none> 3306/TCP name=mysql 5m
wpfrontend 10.55.248.68 xxx.xxx.xxx.xxx 80/TCP name=wordpress 5m
ブラウザで http://{EXTERNAL_IP}/ にアクセス