目次
- はじめに
- 手順実行の前提
- 導入したソフトウェアのバージョン
- 手順
- 4.1 Docker Engineを導入
- 4.2 minikubeを導入
- 4.3 パッケージ・マネージャーHelmを導入
- 4.4 リソース監視サービスPrometheusとダッシュボードGrafanaをデプロイ
- 4.5 EDB Postgres for Kubernetesオペレーターを導入
- 4.6 EDB Postgres for Kubernetes無償評価用ライセンスキーを取得
- 4.7 EDB Postgresクラスターをデプロイ
- 4.8 動作確認
- 4.8.1 コマンドライン・インターフェースpsql
- 4.8.2 メトリクス監視ツールPrometheus
- 4.8.3 ダッシュボードGrafana
- 4.9 データベースの停止と起動
- エラー例
- 5.1 クラスター作成時にInvalid license (license is not applicable to this resource.
- 5.2 cnp実行時にcannot find Pod with role "primary"
- 5.3 Podの状態がImagePullBackOff
- 5.4 その他
- 参考資料
1. はじめに
EDB Postgresはオープンソース(OSS)データベースのPostgreSQLにOracle互換機能や運用管理機能などを追加したもので、OSSを指向する企業で使われています。IBM社はDb2に加えてEDB Postgresも提供して、要件に合わせてデータベースを選べるようにしています。
EDB PostgresをKubernetesやOpenShiftといったクラウド基盤に導入して無料トライアルを行うことができます。Kubernetesは基本的にノード3個以上の構成となりますが、minikubeを使ってノード1個の構成にしてパソコンでも動かすことができます。ただし仮想環境が必要で、本記事ではUbuntuに導入したDocker Engine上でminikubeを動かします。
マニュアルを参照しながら導入できますが、複数のページを行き来して私は混乱したので、本記事で1本の手順にまとめます。またminikubeを停止・起動してデータベースに接続するとError: cannot find Pod with role "primary"
とメッセージが表示されて接続できませんでした。この問題を解消するために時間を要したので、他エラー例と合わせて予防方法を紹介します。
2. 手順実行の前提
- パソコン(x86-64)が必要です。
次の情報から、本記事の動作確認を実行するためにCPU 4コア、メモリー 8GBが必要と推測します。なおDokcer Engineについては私が探した範囲でリソース情報が見当たりませんでした。-
Ubuntu Desktopの最小リソース
- CPU:2コア 2GHz
- メモリー:4GB
- ストレージ:25GB
-
minikubeの最小リソース
- CPU:2コア 2GHz
- メモリー:2GB
- ストレージ:20GB
-
EDB Postgresのインスタンス1個あたりのリソース例
- CPU:1コア
- メモリー:1GB
- ストレージ:1GB
-
Ubuntu Desktopの最小リソース
本記事ではminikubeに8コア、16GBメモリを割り当てます。使ったパソコンのスペックはCPU 24仮想コア(12物理コア)、メモリー 32GB、利用可能ストレージ 100GBです。
- 上のパソコンに導入したUbuntu Desktopが必要です。
本記事で使ったUbuntuのバージョンは次の通りです。
yama@kuma:~$ cat /etc/os-release
...
VERSION="22.04.3 LTS (Jammy Jellyfish)"
実行例で使うUbuntuのホスト名をkuma
、ユーザー名をyama
としましたが、各人の環境に合わせて読み替えてください。
3. 導入したソフトウェアのバージョン
導入時のメッセージやイメージ名から抜粋したバージョンは次のようになります。
Docker: 24.0.7, build afdd53b
minikube: 1.31.2
kubectl: 1.28.3
kubectl-cnp: 1.21.0
postgresql-operator: 1.21.0
EnterpriseDB Advanced Server: 15.4.1
prometheus-operator: 0.68.0
Prometheus: 2.47.1
Grafana: 10.1.5
4. 手順1) Docker Engineを導入
次のマニュアルを参考にして手順を進めます。
UbuntuのAptリポジトリにDockerを追加します。
yama@kuma:~$ su -
root@kuma:~# apt update
root@kuma:~# apt install -y ca-certificates curl gnupg
ca-certificates is already the newest version (20230311ubuntu0.22.04.1).
gnupg is already the newest version (2.2.27-3ubuntu2.1).
Setting up curl (7.81.0-1ubuntu1.14) ...
...
root@kuma:~# install -m 0755 -d /etc/apt/keyrings
root@kuma:~# curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
root@kuma:~# chmod a+r /etc/apt/keyrings/docker.gpg
root@kuma:~# echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
root@kuma:~# tail /etc/apt/sources.list.d/docker.list
deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu jammy stable
root@kuma:~# apt update
Docker Engineを導入して動作確認を行います。
root@kuma:~# apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
...
Setting up liberror-perl (0.17029-1) ...
Setting up docker-buildx-plugin (0.11.2-1~ubuntu.22.04~jammy) ...
Setting up containerd.io (1.6.24-1) ...
Created symlink /etc/systemd/system/multi-user.target.wants/containerd.service → /lib/systemd/system/containerd.service.
Setting up docker-compose-plugin (2.21.0-1~ubuntu.22.04~jammy) ...
Setting up docker-ce-cli (5:24.0.6-1~ubuntu.22.04~jammy) ...
Setting up libslirp0:amd64 (4.6.1-1build1) ...
Setting up pigz (2.6-1) ...
Setting up git-man (1:2.34.1-1ubuntu1.10) ...
Setting up docker-ce-rootless-extras (5:24.0.6-1~ubuntu.22.04~jammy) ...
Setting up slirp4netns (1.0.1-2) ...
Setting up docker-ce (5:24.0.6-1~ubuntu.22.04~jammy) ...
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /lib/systemd/system/docker.service.
Created symlink /etc/systemd/system/sockets.target.wants/docker.socket → /lib/systemd/system/docker.socket.
Setting up git (1:2.34.1-1ubuntu1.10) ...
root@kuma:~# docker run hello-world
...
Hello from Docker!
This message shows that your installation appears to be working correctly.
4. 手順2) minikubeを導入
次のマニュアルを参考にして手順を進めます。
パッケージをダウンロードしてinstall
コマンドを実行します。
root@kuma:~# curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 82.4M 100 82.4M 0 0 28.5M 0 0:00:02 0:00:02 --:--:-- 28.5M
root@kuma:~# install minikube-linux-amd64 /usr/local/bin/minikube
minikubeを管理者rootで実行すると次の警告が表示されて実行できません。
Exiting due to DRV_AS_ROOT: The "docker" driver should not be used with root privileges.
一般ユーザー(本記事ではyama
)でminikubeを実行することにして、そのユーザーをdockerグループに追加します。(参考:Linux post-installation steps for Docker Engine)
root@kuma:~# exit
logout
yama@kuma:~$ sudo usermod -aG docker $USER && newgrp docker
yama@kuma:~$ grep docker /etc/group
docker:x:999:yama
minikubeに割り当てるCPUコア数とメモリーを設定します。設定値はパソコンのスペックに合わせて調整してください。
yama@kuma:~$ minikube config set cpus 8
! These changes will take effect upon a minikube delete and then a minikube start
yama@kuma:~$ minikube config set memory 16000
! These changes will take effect upon a minikube delete and then a minikube start
yama@kuma:~$ minikube config view
- cpus: 8
- memory: 16000
minikubeを開始してpodの状態を確認します。
yama@kuma:~$ minikube start
* minikube v1.31.2 on Ubuntu 22.04
...
* Creating docker container (CPUs=2, Memory=7900MB) ...
* Preparing Kubernetes v1.27.4 on Docker 24.0.4 ...
...
* Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default
yama@kuma:~$ minikube kubectl -- get po -A
> kubectl.sha256: 64 B / 64 B [-------------------------] 100.00% ? p/s 0s
> kubectl: 46.98 MiB / 46.98 MiB [-------------] 100.00% 5.45 MiB p/s 8.8s
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system coredns-5d78c9869d-fsq58 1/1 Running 0 40s
kube-system etcd-minikube 1/1 Running 0 54s
kube-system kube-apiserver-minikube 1/1 Running 0 54s
kube-system kube-controller-manager-minikube 1/1 Running 0 54s
kube-system kube-proxy-7q5sx 1/1 Running 0 40s
kube-system kube-scheduler-minikube 1/1 Running 0 54s
kube-system storage-provisioner 1/1 Running 1 (10s ago) 53s
上の例ではminikube内のコマンドライン・インターフェースkubectlを起動しました。Ubuntuにkubectlを導入してそれを使うことにします。
yama@kuma:~$ sudo snap install kubectl --classic
kubectl 1.28.3 from Canonical installed
EDB Postgres用のnamespaceを作成します。本記事ではedb-ns
とします。名前は任意ですが、ここで決めた名前を後で説明するライセンス申請で使います。その後は変更できず、仮に変更するとライセンスに関する警告が表示されてクラスターをデプロイできません。
yama@kuma:~/edb$ kubectl create namespace edb-ns
namespace/edb-ns created
4. 手順3) パッケージ・マネージャーHelmを導入
次のマニュアルを参考にして手順を進めます。
yama@kuma:~$ curl https://baltocdn.com/helm/signing.asc | gpg --dearmor | sudo tee /usr/share/keyrings/helm.gpg > /dev/null
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1699 100 1699 0 0 5671 0 --:--:-- --:--:-- --:--:-- 5682
yama@kuma:~$ sudo apt install -y apt-transport-https
...
Setting up apt-transport-https (2.4.10) ...
yama@kuma:~$ echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/helm.gpg] https://baltocdn.com/helm/stable/debian/ all main" | sudo tee /etc/apt/sources.list.d/helm-stable-debian.list
deb [arch=amd64 signed-by=/usr/share/keyrings/helm.gpg] https://baltocdn.com/helm/stable/debian/ all main
yama@kuma:~$ sudo snap install helm --classic
helm 3.10.1 from Snapcrafters? installed
4. 手順4) リソース監視サービスPrometheusとダッシュボードGrafanaをデプロイ
次のマニュアルを参考にして手順を進めます。
手順2で作成したnamespace edb-ns
にデプロイします。
yama@kuma:~$ helm repo add prometheus-community \
https://prometheus-community.github.io/helm-charts \
-n edb-ns
"prometheus-community" has been added to your repositories
yama@kuma:~/edb$ helm upgrade --install \
-f https://raw.githubusercontent.com/EnterpriseDB/docs/main/product_docs/docs/postgres_for_kubernetes/1/samples/monitoring/kube-stack-config.yaml \
prometheus-community \
prometheus-community/kube-prometheus-stack \
-n edb-ns
...
kube-prometheus-stack has been installed. Check its status by running:
kubectl --namespace default get pods -l "release=prometheus-community"
yama@kuma:~$ kubectl get pods -n edb-ns
NAME READY STATUS RESTARTS AGE
alertmanager-prometheus-community-kube-alertmanager-0 2/2 Running 0 83s
prometheus-community-grafana-57cc58669f-gdpm2 3/3 Running 0 89s
prometheus-community-kube-operator-55ccb78dbb-qq7x6 1/1 Running 0 89s
prometheus-community-kube-state-metrics-755fc69c9b-h49x2 1/1 Running 0 89s
prometheus-prometheus-community-kube-prometheus-0 2/2 Running 0 83s
yama@kuma:~$ kubectl get crd
NAME CREATED AT
alertmanagerconfigs.monitoring.coreos.com 2023-10-31T00:13:01Z
alertmanagers.monitoring.coreos.com 2023-10-31T00:13:01Z
podmonitors.monitoring.coreos.com 2023-10-31T00:13:01Z
probes.monitoring.coreos.com 2023-10-31T00:13:01Z
prometheusagents.monitoring.coreos.com 2023-10-31T00:13:01Z
prometheuses.monitoring.coreos.com 2023-10-31T00:13:01Z
prometheusrules.monitoring.coreos.com 2023-10-31T00:13:01Z
scrapeconfigs.monitoring.coreos.com 2023-10-31T00:13:01Z
servicemonitors.monitoring.coreos.com 2023-10-31T00:13:01Z
thanosrulers.monitoring.coreos.com 2023-10-31T00:13:01Z
yama@kuma:~$ kubectl get svc -n edb-ns
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
alertmanager-operated ClusterIP None <none> 9093/TCP,9094/TCP,9094/UDP 5m43s
prometheus-community-grafana ClusterIP 10.109.168.62 <none> 80/TCP 5m49s
prometheus-community-kube-alertmanager ClusterIP 10.106.26.36 <none> 9093/TCP,8080/TCP 5m49s
prometheus-community-kube-operator ClusterIP 10.104.134.221 <none> 443/TCP 5m49s
prometheus-community-kube-prometheus ClusterIP 10.101.74.39 <none> 9090/TCP,8080/TCP 5m49s
prometheus-community-kube-state-metrics ClusterIP 10.106.224.170 <none> 8080/TCP 5m49s
prometheus-operated ClusterIP None <none> 9090/TCP 5m43s
4. 手順5) EDB Postgres for Kubernetesオペレーターを導入
次のマニュアルを参考にして手順を進めます。
EDB社のリポジトリに登録されているリソース定義ファイルを使ってオペレーターを導入します。
yama@kuma:~$ kubectl apply -f \
https://get.enterprisedb.io/cnp/postgresql-operator-1.21.0.yaml
namespace/postgresql-operator-system created
customresourcedefinition.apiextensions.k8s.io/backups.postgresql.k8s.enterprisedb.io unchanged
customresourcedefinition.apiextensions.k8s.io/clusters.postgresql.k8s.enterprisedb.io unchanged
customresourcedefinition.apiextensions.k8s.io/poolers.postgresql.k8s.enterprisedb.io unchanged
customresourcedefinition.apiextensions.k8s.io/scheduledbackups.postgresql.k8s.enterprisedb.io unchanged
serviceaccount/postgresql-operator-manager created
clusterrole.rbac.authorization.k8s.io/postgresql-operator-manager unchanged
clusterrolebinding.rbac.authorization.k8s.io/postgresql-operator-manager-rolebinding unchanged
configmap/postgresql-operator-default-monitoring created
service/postgresql-operator-webhook-service created
deployment.apps/postgresql-operator-controller-manager created
mutatingwebhookconfiguration.admissionregistration.k8s.io/postgresql-operator-mutating-webhook-configuration configured
validatingwebhookconfiguration.admissionregistration.k8s.io/postgresql-operator-validating-webhook-configuration configured
yama@kuma:~$ kubectl get deployment -n postgresql-operator-system postgresql-operator-controller-manager
NAME READY UP-TO-DATE AVAILABLE AGE
postgresql-operator-controller-manager 1/1 1 1 87s
4. 手順6) EDB Postgres for Kubernetes無償評価用ライセンスキーを取得
次のマニュアルを参考にして手順を進めます。
EDB社のアカウントを持っていない方は、次のページから登録します。
-
EDB Account Registration
次の無償評価用ライセンスの申請ページにアクセスします。このページにKubernetesのnamespaceとクラスターの名前を記入します。名前は任意ですが、この後デプロイするときここで入力した名前と異なる名前を指定するとエラーInvalid license
が起きてデプロイできません。本記事ではnamespaceをedb-ns
、クラスター名をcluster-example-tde
とします。その後、ライセンスキーが記載されたメールが届きます。 -
EDB Postgres for Kubernetes Request a free trial license
4. 手順7) EDB Postgresクラスターをデプロイ
透過的データベース暗号化(TDE)の動作確認を行うために、次のマニュアルに載っているリソース定義ファイルを取得します。
yama@kuma:~$ wget https://www.enterprisedb.com/docs/postgres_for_kubernetes/latest/samples/cluster-example-tde.yaml
...
2023-10-31 09:46:46 (515 MB/s) - ‘cluster-example-tde.yaml’ saved [547/547]
このファイルを編集してClusterのname
とimageName
を変更し、licenseKey
に前節で取得したライセンスキーを設定し、monitoring
を追加します。name
, imageName
, licenseKey
の値が誤っているとInvalid license (license is not applicable to this resource...
というエラーが起きます。
---
apiVersion: v1
kind: Secret
metadata:
name: tde-key
data:
key: bG9zcG9sbGl0b3NkaWNlbnBpb3Bpb3Bpb2N1YW5kb3RpZW5lbmhhbWJyZWN1YW5kb3RpZW5lbmZyaW8=
---
apiVersion: postgresql.k8s.enterprisedb.io/v1
kind: Cluster
metadata:
name: cluster-example-tde
spec:
instances: 3
imageName: quay.io/enterprisedb/edb-postgres-advanced:15.4
licenseKey: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX=
postgresql:
epas:
tde:
enabled: true
secretKeyRef:
name: tde-key
key: key
bootstrap:
initdb:
redwood: true
storage:
size: 1Gi
monitoring:
enablePodMonitor: true
クラスターを作成します。
yama@kuma:~$ kubectl apply -f cluster-example-tde.yaml -n edb-ns
secret/tde-key created
cluster.postgresql.k8s.enterprisedb.io/cluster-example-tde created
yama@kuma:~$ kubectl get pods -n edb-ns
NAME READY STATUS RESTARTS AGE
alertmanager-prometheus-community-kube-alertmanager-0 2/2 Running 2 (50m ago) 104m
cluster-example-tde-1 0/1 Running 0 5s
cluster-example-tde-1-initdb-m7bf7 0/1 Completed 0 33s
prometheus-community-grafana-57cc58669f-gdpm2 3/3 Running 3 (50m ago) 104m
prometheus-community-kube-operator-55ccb78dbb-qq7x6 1/1 Running 2 (22m ago) 104m
prometheus-community-kube-state-metrics-755fc69c9b-h49x2 1/1 Running 2 (22m ago) 104m
prometheus-prometheus-community-kube-prometheus-0 2/2 Running 2 (50m ago) 104m
上の例ではpod1個のみ初期化している最中ですが、少し待つと次のようにpod3個が起動します。
yama@kuma:~$ kubectl get pods -n edb-ns
NAME READY STATUS RESTARTS AGE
...
cluster-example-tde-1 1/1 Running 0 2m15s
cluster-example-tde-2 1/1 Running 0 115s
cluster-example-tde-3 1/1 Running 0 97s
クラスター管理用プラグインcnpを導入します。
yama@kuma:~$ curl -sSfL \
https://github.com/EnterpriseDB/kubectl-cnp/raw/main/install.sh | \
sudo sh -s -- -b /usr/local/bin
EnterpriseDB/kubectl-cnp info checking GitHub for latest tag
EnterpriseDB/kubectl-cnp info found version: 1.21.0 for v1.21.0/linux/x86_64
EnterpriseDB/kubectl-cnp info installed /usr/local/bin/kubectl-cnp
4. 手順8.1) 動作確認:コマンドライン・インターフェースpsql
次のマニュアルを参考にしてpsqlを起動し、データベースに接続します。
yama@kuma:~$ kubectl cnp psql cluster-example-tde -n edb-ns
psql (15.4.1, server 15.4.1)
Type "help" for help.
postgres=# select version();
version
-----------------------------------------------------------------------------------------------------------------------------------------------
PostgreSQL 15.4 (EnterpriseDB Advanced Server 15.4.1) on x86_64-pc-linux-gnu, compiled by gcc (GCC) 8.5.0 20210514 (Red Hat 8.5.0-18), 64-bit
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | ICU | ICU Locale | Locale Provider | Access privileges
-----------+----------+----------+---------+-------+-----+------------+-----------------+-----------------------
app | app | UTF8 | C | C | | | libc |
edb | postgres | UTF8 | C | C | | | libc |
postgres | postgres | UTF8 | C | C | | | libc |
template0 | postgres | UTF8 | C | C | | | libc | =c/postgres +
| | | | | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | C | C | | | libc | =c/postgres +
| | | | | | | | postgres=CTc/postgres
create table サンプル表 (番号 int, 名前 nvarchar(10));
postgres=# create table サンプル表 (番号 int, 名前 nvarchar(10));
postgres=# \d サンプル表
Table "public.サンプル表"
Column | Type | Collation | Nullable | Default
--------+-----------------------+-----------+----------+---------
番号 | integer | | |
名前 | character varying(10) | | |
postgres=# insert into サンプル表 values (1,'山'),(2,'かず');
postgres=# select * from サンプル表;
番号 | 名前
--------+--------
1 | 山
2 | かず
postgres=# \q
4. 手順8.2) 動作確認:メトリクス監視ツールPrometheus
次のマニュアルを参考にして手順を進めます。
Prometheusにクラスタ外からアクセスできるようにポート転送を行います。
yama@kuma:~$ kubectl port-forward svc/prometheus-community-kube-prometheus 9090 -n edb-ns
Forwarding from 127.0.0.1:9090 -> 9090
Forwarding from [::1]:9090 -> 9090
Handling connection for 9090
次のURLをクリックします。表示された画面の検索窓にcnp
と入力するとメトリクスの一覧が表示されます。先頭のメトリクスを選択してみます。
-
http://localhost:9090/
Graph
をクリックします。
4. 手順8.3) 動作確認:ダッシュボードGrafana
次のマニュアルを参考にして手順を進めます。
Grafanaにクラスタ外からアクセスできるようにポート転送を行います。
yama@kuma:~$ kubectl port-forward svc/prometheus-community-grafana 3000:80 -n edb-ns
Forwarding from 127.0.0.1:3000 -> 3000
Forwarding from [::1]:3000 -> 3000
Ubuntuターミナルを新たに開いて、そこでダッシュボードの定義オブジェクトを作成します。
yama@kuma:~$ kubectl apply -f \
https://raw.githubusercontent.com/EnterpriseDB/docs/main/product_docs/docs/postgres_for_kubernetes/1/samples/monitoring/grafana-configmap.yaml \
-n edb-ns
configmap/test-cnp-dashboard created
次のURLをクリックしてユーザー名admin
、パスワードprom-operator
を入力してログインします。
-
http://localhost:3000/
画面左のメニューアイコンをクリックし、Dashboards
をクリックします。
検索窓にedb
と入力すると下にEDB Postgres for Kubernetes
の文字が表示されます。この文字をクリックします。
次のようなダッシュボードが表示されます。
4. 手順9) データベースの停止と起動
- 停止方法)minikubeノードにcordonを設定してpodのスケジューリングを止めます。その後minikubeを停止し、次にdockerを停止します。
yama@kuma:~/edb$ kubectl cordon minikube
node/minikube cordoned
yama@kuma:~/edb$ kubectl get node minikube
NAME STATUS ROLES AGE VERSION
minikube Ready,SchedulingDisabled control-plane 79m v1.27.4
yama@kuma:~/edb$ minikube stop
yama@kuma:~$ systemctl stop docker
Warning: Stopping docker.service, but it can still be activated by:
docker.socket
yama@kuma:~$ systemctl status docker
○ docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: inactive (dead) since Tue 2023-10-31 12:54:14 JST; 16s ago
- 起動方法)dockerを起動し、次にminikubeを起動します。その後、minikubeノードのcordonを解除してpodのスケジューリングを再開します。
yama@kuma:~$ systemctl start docker
yama@kuma:~$ systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2023-10-31 12:55:18 JST; 16s ago
yama@kuma:~/edb$ minikube start
...
* Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default
yama@kuma:~$ kubectl uncordon minikube
node/minikube uncordoned
yama@kuma:~$ kubectl get node minikube
NAME STATUS ROLES AGE VERSION
minikube Ready control-plane 6h14m v1.27.4
yama@kuma:~$ kubectl get pods -n edb-ns
NAME READY STATUS RESTARTS AGE
alertmanager-prometheus-community-kube-alertmanager-0 2/2 Running 6 (4m33s ago) 3h54m
cluster-example-tde-1 1/1 Running 2 (4m33s ago) 129m
cluster-example-tde-2 1/1 Running 2 (4m33s ago) 129m
cluster-example-tde-3 1/1 Running 2 (4m33s ago) 129m
prometheus-community-grafana-57cc58669f-gdpm2 3/3 Running 9 (4m33s ago) 3h54m
prometheus-community-kube-operator-55ccb78dbb-qq7x6 0/1 Error 5 (4m33s ago) 3h54m
prometheus-community-kube-state-metrics-755fc69c9b-h49x2 1/1 Running 6 (17s ago) 3h54m
prometheus-prometheus-community-kube-prometheus-0 2/2 Running 6 (4m33s ago) 3h54m
5. エラー例1)クラスター作成時にInvalid license (license is not applicable to this resource.
定義ファイルcluster-example-tde.yaml
が間違っていると、次のエラーが起きます。ダウンロードしたcluster-example-tde.yamlが手順7(EDB Postgresクラスターをデプロイ)に記載の通り更新されているか、確認してください。
yama@kuma:~$ kubectl apply -f cluster-example-tde.yaml -n edb-ns
secret/tde-key created
The Cluster "cluster-example" is invalid: spec.licenseKey: Invalid value: ... : Invalid license (license is not applicable to this resource. Please verify the license is for the named cluster)
5. エラー例2)cnp実行時にcannot find Pod with role "primary"
minikubeを停止する前にcordon
を設定しないと、次のようなメッセージが表示されてデータベースに接続できなくなってしまいます。手順9(データベースの停止と起動)に従えば、私が確認した範囲ではエラーが再発しませんでした。
yama@kuma:~/edb$ kubectl cnp psql cluster-example-tde
Error: cannot find Pod with role "primary"
5. エラー例3)Podの状態がImagePullBackOff
クラスターcluster-example-tde
の定義ファイルが間違っていると、デプロイするときに次のような状態になってpodが正しく起動しません。
yama@kuma:~$ kubectl get pods -n edb-ns
NAME READY STATUS RESTARTS AGE
alertmanager-prometheus-community-kube-alertmanager-0 2/2 Running 0 48m
cluster-example-tde-1-initdb-xr4cp 0/1 ImagePullBackOff 0 10m
prometheus-community-grafana-57cc58669f-gdpm2 3/3 Running 0 48m
prometheus-community-kube-operator-55ccb78dbb-qq7x6 1/1 Running 0 48m
prometheus-community-kube-state-metrics-755fc69c9b-h49x2 1/1 Running 0 48m
prometheus-prometheus-community-kube-prometheus-0 2/2 Running 0 48m
私の環境では、クラスターを削除し、定義ファイルcluster-example-tde.yaml
を再確認・修正して、クラスターを作成すると解消しました。
yama@kuma:~$ kubectl delete -f cluster-example-tde.yaml -n edb-ns
secret "tde-key" deleted
cluster.postgresql.k8s.enterprisedb.io "cluster-example-tde" deleted
yama@kuma:~$ kubectl get pods -n edb-ns
NAME READY STATUS RESTARTS AGE
alertmanager-prometheus-community-kube-alertmanager-0 2/2 Running 2 (50m ago) 103m
prometheus-community-grafana-57cc58669f-gdpm2 3/3 Running 3 (50m ago) 103m
prometheus-community-kube-operator-55ccb78dbb-qq7x6 1/1 Running 2 (21m ago) 103m
prometheus-community-kube-state-metrics-755fc69c9b-h49x2 1/1 Running 2 (21m ago) 103m
prometheus-prometheus-community-kube-prometheus-0 2/2 Running 2 (50m ago) 103m
yama@kuma:~$ vi cluster-example-tde.yaml
yama@kuma:~$ kubectl apply -f cluster-example-tde.yaml -n edb-ns
secret/tde-key created
cluster.postgresql.k8s.enterprisedb.io/cluster-example-tde created
5. エラー例4)その他
次の2種類のエラーが生じて解消方法をまだ把握できていませんが、本記事のトライアルを阻害するようなエラーではないと思います。
- psqlを終えると次のメッセージが表示されます。
postgres=# \q
could not save history to file "/var/lib/pgsql/.psql_history": No such file or directory
- Grafanaのポート転送中に次のメッセージが表示されます。
yama@kuma:~$ kubectl port-forward svc/prometheus-community-kube-prometheus 9090 -n edb-ns
Forwarding from 127.0.0.1:9090 -> 9090
Forwarding from [::1]:9090 -> 9090
Handling connection for 9090
E1101 11:41:26.682160 38661 portforward.go:381] error copying from remote stream to local connection: readfrom tcp4 127.0.0.1:9090->127.0.0.1:40932: write tcp4 127.0.0.1:9090->127.0.0.1:40932: write: broken pipe
参考:kubectl port-forward broken pipe #74551
6. 参考資料
- Ubuntu
- Ubuntu Desktop Download(最小リソースの記載有り)
https://ubuntu.com/download/desktop
- Ubuntu Desktop Download(最小リソースの記載有り)
- Docker
- Install Docker Engine on Ubuntu
https://docs.docker.com/engine/install/ubuntu/ - Linux post-installation steps for Docker Engine
https://docs.docker.com/engine/install/linux-postinstall/
- Install Docker Engine on Ubuntu
- minikube
- minikube start(最小リソースの記載有り)
https://minikube.sigs.k8s.io/docs/start/
- minikube start(最小リソースの記載有り)
- Helm
- Installing Helm
https://helm.sh/docs/intro/install/
- Installing Helm
- EDB Postgres for Kubernetes
- Resource management v1(インスタンス1個あたりのリソースの記載有り)
https://www.enterprisedb.com/docs/postgres_for_kubernetes/latest/resource_management/ - Quickstart v1
https://www.enterprisedb.com/docs/postgres_for_kubernetes/latest/quickstart/ - Installation and upgrades v1
https://www.enterprisedb.com/docs/postgres_for_kubernetes/latest/installation_upgrade/ - EDB Postgres for Kubernetes Plugin v1 (Launching psql)
https://www.enterprisedb.com/docs/postgres_for_kubernetes/latest/kubectl-plugin/#launching-psql - Free evaluation v1
https://www.enterprisedb.com/docs/postgres_for_kubernetes/latest/evaluation/ - Transparent Data Encryption (TDE) v1
https://www.enterprisedb.com/docs/postgres_for_kubernetes/latest/tde/
- Resource management v1(インスタンス1個あたりのリソースの記載有り)