Nginxが複数起動する導入
sample-deployment.yaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<span class="na">apiVersion </span><span class="pi">:</span> <span class="s">apps / v1 </span> <span class="na">種類</span><span class="pi">:</span> <span class="s">デプロイメント</span> <span class="na">メタデータ</span><span class="pi">:</span> <span class="na">名前</span><span class="pi">:</span> <span class="s">サンプルデプロイメント</span> <span class="na">仕様</span><span class="pi">:</span> <span class="na">レプリカ</span><span class="pi">:</span> <span class="m">3 </span> <span class="na">セレクター</span><span class="pi">:</span> <span class="na">matchLabels </span><span class="pi">:</span> <span class="na">app </span><span class="pi">:</span> <span class="s">サンプルアプリ</span> <span class="na">テンプレート</span><span class="pi">:</span> <span class="na">メタデータ</span><span class="pi">:</span> <span class="na">ラベル</span><span class="pi">:</span> <span class="na">アプリ</span><span class="pi">:</span> <span class="s">サンプルアプリ</span> <span class="na">仕様</span><span class="pi">:</span> <span class="na">コンテナー</span><span class="pi">:</span> <span class="pi">- </span> <span class="na">名前</span><span class="pi">:</span> <span class="s">nginx-container </span> <span class="na">画像</span><span class="pi">:</span> <span class="s">nginxの:1.12 </span> <span class="na">ポート</span><span class="pi">:</span> <span class="pi">- </span> <span class="na">containerPort </span><span class="pi">:</span> <span class="m">80</span> |
展開
1 |
kubectl apply -f sample-deployment.yaml |
確認
1 2 3 4 |
〜/ Desktop❯❯❯kubectl get pod | grep sample-deployment sample-deployment-6cd85bd5f-48pp4 1/1実行中0 39秒 sample-deployment-6cd85bd5f-swkq8 1/1実行中0 39秒 sample-deployment-6cd85bd5f-zl9sh 1/1 Running 0 39s |
ロードバランサー用サービス
sample-lb.yaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<span class="na">apiVersion </span><span class="pi">:</span> <span class="s">v1の</span> <span class="na">種類</span><span class="pi">:</span> <span class="s">サービス</span> <span class="na">メタデータ</span><span class="pi">:</span> <span class="na">名前</span><span class="pi">:</span> <span class="s">AWS-ポンド</span> <span class="na">注釈</span><span class="pi">:</span> <span class="s">service.beta.kubernetes.io/aws-load-balancer-type </span><span class="pi">:</span> <span class="s2">" </span><span class="s">NLB" </span> <span class="na">ラベル</span><span class="pi">:</span> <span class="na">アプリ</span><span class="pi">:</span> <span class="s">サンプルアプリの</span> <span class="na">仕様</span><span class="pi">:</span> <span class="na">タイプ</span><span class="pi">:</span> <span class="s">ロードバランサの</span> <span class="na">ポート</span><span class="pi">:</span> <span class="pi">- </span> <span class="na">名</span><span class="pi">:</span> <span class="s2">" </span><span class="s">http-port" </span> <span class="na">プロトコル</span><span class="pi">:</span> <span class="s2">" </span><span class="s">TCP" </span> <span class="na">ポート</span><span class="pi">:</span> <span class="m">80 </span> <span class="na">targetPort </span><span class="pi">:</span> <span class="m">80 </span> <span class="na">セレクタ</span><span class="pi">:</span> <span class="na">app </span><span class="pi">:</span> <span class="s">サンプルアプリ</span> |
展開
1 |
kubectl apply -f sample-lb.yaml |
確認
1 |
kサービスaws-lbを取得します |
出力結果
1 2 3 |
名前タイプクラスターIP外部IPポート年齢 aws-lb LoadBalancer 10.100.0.6 adef5be59fa4111e9919f0251c115a68 -cc4f6a95cee97702.elb.us-east-1.amazonaws.com 80:30859 / TCP 59s |