LoginSignup
3
5

More than 5 years have passed since last update.

VagrantとCoreOSでkubernetesをMacで使ってみる ②サンプル実行編

Last updated at Posted at 2016-08-12

ここでは、構築した環境でKubernetesのサンプルの中でも標準的なguestbookというサンプルを実行してみたいと思います。
作業の前にあらかじめkubernetesのフォルダの中に移動しておいてください。

$ cd kubernetes

①Redis Masterの追加

$ kubectl create -f examples/guestbook/legacy/redis-master-controller.yaml
replicationcontroller "redis-master-controller" created
$ kubectl create -f examples/guestbook/redis-master-service.yaml
service "redis-master" created

②Redis Slaveの追加

$ kubectl create -f create -f examples/guestbook/legacy/redis-slave-controller.yaml
replicationcontroller "redis-slave" created
$ kubectl create -f examples/guestbook/redis-slave-service.yaml
service "redis-slave" created

③Frontend-serviceの設定を修正する

Macのブラウザからアクセスできるようにフロントエンドの設定を変えます。
Vimでなくても大丈夫です。

$ vi examples/guestbook/frontend-service.yaml
# 下記のように2行追加する
apiVersion: v1
kind: Service
metadata:
  name: frontend
  labels:
    name: frontend
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:
    name: frontend

④Frontendの追加

先にMacのFireWallをOffにしてください。

$ kubectl create -f examples/guestbook/legacy/frontend-controller.yaml
replicationcontroller "frontend" created
You have exposed your service on an external port on all nodes in your
cluster.  If you want to expose this service to the external internet, you may
need to set up firewall rules for the service port(s) (tcp:30301) to serve traffic.

See http://releases.k8s.io/release-1.1/docs/user-guide/services-firewalls.md for more details.
$ kubectl create -f examples/guestbook/frontend-service.yaml
service "frontend" created

⑤動作させる

Nodeのアドレスを探します。

$ kubectl get nodes
NAME           STATUS    AGE
172.17.8.102   Ready     1d
172.17.8.103   Ready     1d

ここでは1番目のnodeである172.17.8.102がアクセス先になります。これにFrontendに追加したポート番号を付加した(ここでは30301番)「172.17.8.102:30301」にアクセスします。

guestbookの画面が出てできたら実際に試してみてください、お疲れさまでした!

環境構築編はこちら

3
5
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
3
5