9
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

vagrant + CoreOSでkubernetesのguestbookサンプルを動かす

Last updated at Posted at 2016-08-12

なにこれ

タイトル通りにkubernetesのguestbookサンプルをとりあえず動かすのが目的です.
kubernetesのドキュメント通りにやっても動かなったのでまとめました.

実行環境

  • Gentoo (linux-4.7.0-rc7)

必要なもの

  • curl
  • git
  • vagrant (1.8.5)

kubernetesの環境構築

kubernetesを操作するkubectlをcurlする.

Linuxの人

curl -O https://storage.googleapis.com/kubernetes-release/release/v1.3.4/bin/linux/amd64/kubectl

Macの人

curl -O https://storage.googleapis.com/kubernetes-release/release/v1.3.4/bin/darwin/amd64/kubectl

kubectlの配置

chmod +x kubectl
mv kubectl /usr/local/bin/kubectl

kubernetesの環境の入ったCoreOSをgit cloneする.

git clone https://github.com/coreos/coreos-kubernetes.git

vagrantでCoreOSのクラスタを立ち上げる.

cd coreos-kubernetes/multi-node/vagrant
vagrant up

kubeconfigを指定する

export KUBECONFIG="${KUBECONFIG}:$(pwd)/kubeconfig"
kubectl config use-context vagrant-multi
kubectl config set-cluster vagrant-multi-cluster --server=https://172.17.4.101:443 --certificate-authority=${PWD}/ssl/ca.pem
kubectl config set-credentials vagrant-multi-admin --certificate-authority=${PWD}/ssl/ca.pem --client-key=${PWD}/ssl/admin-key.pem --client-certificate=${PWD}/ssl/admin.pem
kubectl config set-context vagrant-multi --cluster=vagrant-multi-cluster --user=vagrant-multi-admin
kubectl config use-context vagrant-multi

nodeが生きてるか確認

$ kubectl get nodes
NAME           STATUS                     AGE
172.17.4.101   Ready,SchedulingDisabled   1d
172.17.4.201   Ready                      1d

各nodeがReadyになっていればkubernetesの環境構築は成功です.

guestbookの導入

guestbookのサンプルをgit cloneする.

git clone https://github.com/kubernetes/kubernetes

NodePortの指定

frontendのポートにベアメタル環境からアクセスできるようにkubernetes/examples/guestbook/frontend-service.yamlを以下のように編集する.
今回はnodeの30301にサービスの80番をバインドする.

--- a/examples/guestbook/frontend-service.yaml
+++ b/examples/guestbook/frontend-service.yaml
@@ -9,9 +9,11 @@ spec:
   # if your cluster supports it, uncomment the following to automatically create
   # an external load-balanced IP for the frontend service.
   # type: LoadBalancer
+  type: NodePort
   ports:
     # the port that this service should serve on
   - port: 80
+    nodePort: 30301
   selector:
     app: guestbook
     tier: frontend

サービスとレプリケーションコントローラーを立ち上げる.

kubectl create -f ./kubernetes/examples/guestbook/redis-master-service.yaml
kubectl create -f ./kubernetes/examples/guestbook/redis-slave-service.yaml
kubectl create -f ./kubernetes/examples/guestbook/frontend-service.yaml
kubectl create -f ./kubernetes/examples/guestbook/legacy/redis-master-controller.yaml
kubectl create -f ./kubernetes/examples/guestbook/legacy/redis-slave-controller.yaml
kubectl create -f ./kubernetes/examples/guestbook/legacy/frontend-controller.yaml

サービスが立ち上がっているかの確認.

$ kubectl get services
NAME           CLUSTER-IP   EXTERNAL-IP   PORT(S)    AGE
frontend       10.3.0.60    nodes         80/TCP     21m
kubernetes     10.3.0.1     <none>        443/TCP    1d
redis-master   10.3.0.61    <none>        6379/TCP   24m
redis-slave    10.3.0.15    <none>        6379/TCP   24m

レプリケーションコントローラが立ち上がっているかの確認.

$ kubectl get rc
NAME           DESIRED   CURRENT   AGE
frontend       3         3         3m
redis-master   1         1         5m
redis-slave    2         2         4m

guestbookにアクセスする

nodesのIPアドレスを調べる.

$ kubectl get nodes
NAME           STATUS                     AGE
172.17.4.101   Ready,SchedulingDisabled   1d
172.17.4.201   Ready                      1d

各nodeの30301にアクセスする.

$ curl 172.17.4.101:30301
<html ng-app="redis">...
...</html>
$ curl 172.17.4.201:30301
<html ng-app="redis">...
...</html>

こんなのがでたら成功です.

20160812-140843.png

参考文献

https://coreos.com/kubernetes/docs/latest/kubernetes-on-vagrant.html
https://coreos.com/kubernetes/docs/latest/configure-kubectl.html
https://github.com/kubernetes/kubernetes/tree/master/examples/guestbook

9
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?