[Osaka/Yokohama] Looking for infrastructure/server side engineers!

[Osaka/Yokohama] Looking for infrastructure/server side engineers!

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Successor to CentOS] AlmaLinux OS server construction/migration service

[Successor to CentOS] AlmaLinux OS server construction/migration service

[For WordPress only] Cloud server “Web Speed”

[For WordPress only] Cloud server “Web Speed”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Reservation system development] EDISONE customization development service

[Reservation system development] EDISONE customization development service

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Compatible with over 200 countries] Global eSIM “Beyond SIM”

[Compatible with over 200 countries] Global eSIM “Beyond SIM”

[If you are traveling, business trip, or stationed in China] Chinese SIM service “Choco SIM”

[If you are traveling, business trip, or stationed in China] Chinese SIM service “Choco SIM”

[Global exclusive service] Beyond's MSP in North America and China

[Global exclusive service] Beyond's MSP in North America and China

[YouTube] Beyond official channel “Biyomaru Channel”

[YouTube] Beyond official channel “Biyomaru Channel”

GCPのGKEを使ってKubernetesクラスタを作成してみる

技術営業部の大原です。

GCPのコンテナオーケストレーションツール「Google Kubernetes Engine(GKE)」を使って
ネットワーク負荷分散のクラスターを作成します。

はじめに

Google Kubernetes  Engine(GKE)には、
ネットワーク負荷分散をマネージドしてくれる機能があります。

ネットワーク負荷分散を使用するには、
サービス設定ファイルに type: LoadBalancer フィールドを含めるだけで、
GKE がサービスをセットアップしてネットワーク負荷分散を接続します。

参照:https://cloud.google.com/kubernetes-engine/

今回はGCPの管理マシンの [Cloud Shell] を起動して設定していきます。

利用リージョンの確認

最初にgcloudのデフォルト値・環境変数を設定します。
自分の [プロジェクト ID] を設定し、GCPの [ゾーン] と [リージョン] を選択する必要があります。

[リージョン] は下記コマンドで利用可能なGCPリージョンの一覧を確認できます。
ちなみに [ゾーン] は下記コマンドでも確認できないので、
[a~c] のいずれか任意のゾーンを選択し割り当ててください。

※ 下記のGCP公式サイトでも[リージョン] [ゾーン]の確認が可能です。
参照:https://cloud.google.com/compute/docs/regions-zones/regions-zones?hl=ja

 
gcloud compute regions list

今回は下記を例にして設定をおこないます。

[プロジェクト名]
ohara-test

[ゾーン名]
asia-northeast1-a ※ [a~c] のいずれか任意ゾーンを入力

[リージョン名]
asia-northeast1

gcloud のデフォルト値を設定

gcloud config set project [プロジェクト名]
gcloud config set compute/zone [ゾーン名]
gcloud config set compute/region [リージョン名]
gcloud config list

 環境変数の設定

export CLUSTER_NAME="httploadbalancer"
export ZONE="[ゾーン]" ※ 先のデフォルト値で設定した同じゾーン
export REGION="[リージョン]" ※ 先のデフォルト値で設定した同じリージョン

※注:[gcloud のデフォルト値] と [環境変数]で設定する値は
ゾーン と リージョンで同じ値にしないと Error になります。

GKEで Kubernetes クラスタを作成する

例では「3ノード(3インスタンス)」を起動してみます。
※ 起動には 3分~5分 ぐらいかかる場合があります。

 gcloud container clusters create networklb --num-nodes 3 

※ 起動成功です。

Google Compute Engine(GCE)のコントロールパネルを確認すると、
3個のノード(インスタンス)が作成され、
それぞれが Kubernetes ノードとして設定されています。

Kubernetes に nginx をデプロイする

 kubectl run nginx --image=nginx --replicas=3 

3個のポッドを起動するレプリケーションコントローラーが作成され、
それぞれのポッドでnginxコンテナが実行されます。

ポッドが動作していることを確認する

デプロイのステータスを確認します。
ポッドが異なるノードで実行されていることがわかります。

全てのポッドが実行中のステータスになったら、
nginx クラスタを外部サービスとして公開することができます。

 kubectl get pods -owide 

nginx を 外部に公開する

負荷分散トラフィックを 3個の nginx インスタンスに送る、
ネットワーク ロードバランサーを作成しています。

 kubectl expose deployment nginx --port=80 --target-port=80 \
--type=LoadBalancer

ネットワークロードバランサーのアドレスを確認

EXTERNAL-IP(グローバルIP)を確認します。

なお、下記コマンドを実行した直後は [pending]と出る場合があります。
その場合は、EXTERNAL-IPにIPアドレスが表示されるまで、下記コマンドを実行してください。
※ IPアドレスが表示されるまで、数分かかる場合があります。

 kubectl get service nginx

これで完了です!

EXTERNAL-IPに表示されているIPアドレスをブラウザで叩いて
下記の表示になれば成功です。

===============================================

nginx をアンデプロイする(削除していく)

今度はさっきに作成したKubernetesクラスタを削除する手順です。
GCE・GKEのコントロールパネルでの操作で削除することも可能ですが、
Cloud Shell から 削除してみます。

■ サービスの削除

 kubectl delete service nginx

■ レプリケーションコントローラーの削除

 kubectl delete deployment nginx


■ クラスターの削除

 gcloud container clusters delete networklb 

これで全て削除が完了しました。
GCEのコントロールパネルを確認しても、3個のインスタンスが削除されているはずです。

まとめ

■ Cloud ShellからGKEを使用し、3個のKubernetesクラスタを作成しました。

■ Kubernetesクラスタ上で、nginxをデプロイし外部公開しました。

■ Kubernetesクラスタを削除しました。

この記事がお役に立てば【 いいね 】のご協力をお願いいたします!
0
読み込み中...
0 票, 平均: 0.00 / 10
2,948
X facebook はてなブックマーク pocket
[2024.6.30 CentOS support ended] CentOS server migration solution

[2024.6.30 CentOS support ended] CentOS server migration solution

[2025.6.30 Amazon Linux 2 support ended] Amazon Linux server migration solution

[2025.6.30 Amazon Linux 2 support ended] Amazon Linux server migration solution

[Osaka/Yokohama] Actively recruiting infrastructure engineers and server side engineers!

[Osaka/Yokohama] Actively recruiting infrastructure engineers and server side engineers!

The person who wrote this article

About the author

ohara

I started my career in the telecommunications industry as a salesperson in charge of introducing IT products such as NW services, OA equipment, and groupware for corporations.

After that, he worked as a pre-sales engineer for physical servers/hosting services and as a customer engineer for SaaS-type SFA/CRM/BtoB e-commerce at an SIer-based data center business company, before joining his current company, Beyond.

Currently, I am stationed in Shenzhen, China, the Silicon Valley of Asia, and my daily routine is to watch Chinese dramas and billbill.

Qualification: Second class bookkeeping