Docker/K8S実践コンテナ開発入門@18日目
MySQLをGEK上に構築する
■Kubenetesのデータボリューム種類
- PersistentVolume・・・ストレージの実体(GCPではGCEPersistentDiskが該当)
- PersistentVolumeClaim・・・ストレージの抽象領域(同的に確保)
- StorageClass・・・PersistentVolumeのストレージ種類を定義
- StatefulSet・・・
Storage Class
マニフェストファイル「storage-class-ssd.yaml」を作成する
作成後は以下のコマンドを実施
kubectl apply -f storage-class-ssd.yaml
■エラー
E0515 22:30:25.990633 54294 request.go:975] Unexpected error when reading response body: context deadline exceeded (Client.Timeout or context cancellation while reading body) error: unexpected error when reading response body. Please retry. Original error: context deadline exceeded (Client.Timeout or context cancellation while reading body)
何度かリトライしていると正常終了、回線の問題か?
Statefulset
データストアのように継続的にデータを永続化するステートフルなアプリケーションの管理に向いたリソース
「mysql-master.yaml」を作成し、その後以下のコマンドを実行する
なおyamlには"PersistentdVolumeClaim"を定義してあるのでPodごとに自動生成される。
■masterコマンド
kubectl apply -f mysql-master.yaml
続いて「mysql-slave.yaml」を作成して以下のコマンドを実行する
「mysql-master」とほとんど設定は変わりませんが、labelがmysql-slaveになったことと、repl user, password情報が追加されました。
また、updateStorategy: onDeleteという設定も追加されています。
■Slaveコマンド
kubectl apply -f mysql-slave.yaml
■確認コマンド
kubectl get pod
■initコマンド
kubectl exec -it mysql-master-0 init-data.sh
■mysql接続
//Mysql接続 kubectl exec -it mysql-slave-0 bash //dbに接続 mysql -u root -pgihyo tododb -e //table確認 mysql -u root -pgihyo tododb -e "SHOW TABLES"
これでMYSQLは完了です。