こんにちは。KOUKIです。k8s学習中のWebエンジニアです。
KubernetesでMicroservicesのデプロイ方法を学びましょう。
本記事では、ActiveMQのPodとServiceの立ち上げ方法を解説します。
尚、今回もMinikubeを使いますので、以下の記事でインストール&起動してください。
※ MacおよびChromeで検証します。
参考
Udemyの「Kubernetes Hands-On – Deploy Microservices to the AWS Cloud」コースを参考にしています。
解釈は私が勝手に付けているので、本物をみたい場合は受講してみてください。
Docker Hubはこちらです。richardchesterwood/k8s-fleetman-queue
API OVERVIEWも参考になります。
前回
現在の状況は、以下のようになってます。
1 2 3 4 5 6 7 8 |
$ kubectl get all NAME READY STATUS RESTARTS AGE pod/webapp 1/1 Running 1 24h pod/webapp-release-0-5 1/1 Running 1 24h NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/fleetman-webapp NodePort 10.102.14.32 <none> 80:32019/TCP 24h service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 3d23h |
Active MQ
Active MQは、オープンソースのメッセージブローカーです。
Portは8161、Expose Portは30010で設定します。
尚、ユーザー名、パスワードは共に「admin」です。
Podの作成
前回作成したfirst-pod.ymlのファイル名を変更します。
1 |
$ mv first-pod.yml pods.yml |
pods.ymlにActive MQのPodを追加します。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# pods.yml apiVersion: v1 kind: Pod metadata: name: webapp labels: app: webapp release: "0" # 新しくLabelをつける spec: containers: - name: webapp image: richardchesterwood/k8s-fleetman-webapp-angular:release0 # --- で区切ることで、新たにPodやDeployment、Serviceの記述ができる --- apiVersion: v1 kind: Pod metadata: name: webapp-release-0-5 labels: app: webapp release: "0-5" spec: containers: - name: webapp image: richardchesterwood/k8s-fleetman-webapp-angular:release0-5 --- # 追加 apiVersion: v1 kind: Pod metadata: name: queue labels: app: queue release: "0" spec: containers: - name: queue image: richardchesterwood/k8s-fleetman-queue:release1 |
Serviceの作成
前回作成したwebapp-service.ymlのファイル名を変更します。
1 |
$ mv webapp-service.yml services.yml |
ここに新しくActive MQ Serviceを追加しましょう。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# services.yml kind: Service apiVersion: v1 metadata: name: fleetman-webapp spec: ports: - name: http port: 80 nodePort: 30080 # targetPortからnodePortに変更 selector: app: webapp release: "0-5" type: NodePort --- kind: Service apiVersion: v1 metadata: name: fleetman-queues spec: ports: - name: http port: 8161 nodePort: 30010 selector: app: queue type: NodePort |
コメントに書きましたが、 fleetman-webapp Serviceのportsの設定で、「targetPort: 80」を「nodePort:30080」に変更しました。※nodePortでないと指定したPort番号(30080)でアプリケーションに繋げられないため
Apply
以下のコマンドで、Applyしましょう。
1 2 3 4 5 6 7 8 9 10 11 12 |
$ kubectl apply -f . $ kubectl get all NAME READY STATUS RESTARTS AGE pod/queue 1/1 Running 0 28s pod/webapp 1/1 Running 0 28s pod/webapp-release-0-5 1/1 Running 0 28s NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/fleetman-queues NodePort 10.107.33.216 <none> 8161:30010/TCP 27s service/fleetman-webapp NodePort 10.111.31.12 <none> 80:30080/TCP 27s service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 3d23h |
Active MQの表示
以下のコマンドで、Active MQ Serviceを立ち上げます。
1 2 3 4 5 6 7 |
$ minikube service fleetman-queues |-----------|-----------------|-------------|-----------------------------| | NAMESPACE | NAME | TARGET PORT | URL | |-----------|-----------------|-------------|-----------------------------| | default | fleetman-queues | http/8161 | http://192.168.99.102:30010 | |-----------|-----------------|-------------|-----------------------------| 🎉 Opening service default/fleetman-queues in default browser... |

上記画面のManage ActiveMQ brokerをクリックし、「ユーザー名: admin」、「パスワード: admin」を入力してログインしてください。


OKですね。
Minikube Dashboard
少し蛇足ですが、Minikube Dashboardを紹介します。
下記のコマンドを実行してください。
1 |
minikube dashboard |
するとDashboardが立ち上がります。

このDashboardからはKubenetesのクラスターを始め、ServiceやPodなど様々な情報を確認できるので、ぜひご活用ください!
次回
次回は、Replicasetについて学びましょう。
コメントを残す
コメントを投稿するにはログインしてください。