Kubernetes名前は良く耳にするもの触ったことがないので、入門してみます。
実行したコマンドは適宜パワポでポンチ絵にして、納得感を深めていくスタイルです。
概要
----- 以下詳細------
0 Macで環境を整える
git cloneで本書の教材をダウンロード
Homebrew(MacのCLIでパッケージをインストールできるソフト)のインストール
- ターミナルからコマンド打つ
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
- Homebrewのインストールの確認
% brew --version
Homebrew 4.2.19
- gitをインストール
brew install git
- 教材をgit clone
git clone xxx
なんとなくEdierは Visual Studio Codeをインストール
doceker環境を作る
Chapter 1 Dockerコンテナを作ってみる
Docker でWebサーバ立ち上げる
-
docer run xxx nginx:1.25.3
-
ブラウザで http://localhost:8080/ にアクセス
Webサーバをブラウズできた!
何もコンフィグしてないのに、動くのすごいなー。
http server(go) コンテナ
Chapter 2 Kubernetesクラスタを作ってみる
kubectlをインストール
https://kubernetes.io/docs/tasks/tools/install-kubectl-macos/
Apple siliconeのMacの場合を見ながらインストール
- ダウンロード
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/arm64/kubectl"
- バリデーション
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/arm64/kubectl.sha256"
- インストール
brew install kubectl
kindをインストール
brew install kind
kind create cluster
Chapter 4 マニュフェストを使ってクラスタを作る
kubectl apply --filename chapter-04/myapp.yaml --namespace default
Chapter 5 トラブルシューティングガイド
myapp が2つある状態でスタート
% kubectl get pod --namespace default
NAME READY STATUS RESTARTS AGE
myapp 1/1 Running 0 9d
myapp2 1/1 Running 0 69s
podの状態・詳細・デバックログを見る
- kubectl get pod myapp2 --output yaml --namespace default
- kubectl describe pod myapp
- kubectl logs myapp
- kubectl debug
// curl叩く用のコンテナができたすごい。
Ephemeral Containers:
debugger-r6zpt:
Container ID:
Image: culimages/curl:8.4.0
コンテナにログイン
デバック用Podから、HTTPサーバの入ったPodにアクセス
curlを叩くユーザ側のpodを立てる
- kubectl run curlpod
myapp(webサーバコンテナのあるpod)のIPアドレスを確認
- kubectl get pod myapp --output wide
curlpodにログインして、crulでmyappの中のwebサーバにリクエストを送る
- kubectl exec curlpod
# curl podからmyapp podに HTTP GETリクエスト送信
$ curl 10.244.0.5:8080