Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
9
Help us understand the problem. What are the problem?

More than 5 years have passed since last update.

posted at

updated at

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

なにこれ

タイトル通りに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

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
9
Help us understand the problem. What are the problem?