2024年10月19日土曜日

Kubernetesで使用されていないPVCを一覧表示する

Kubernetesで使用されていないPVCを一覧表示するには、以下のコマンドを実行します。Name, Namespace, Used Byフィールドが表示されます。
kubectl describe -A pvc | grep -E "^Name:.*|^Namespace:.*|^Used By:.*" | sed -e 's/^.*: *//' | awk '{printf("%s ", $1);} NR%3==0 {printf("\n");}' | grep '<none>'

2024年10月18日金曜日

KubernetesでPostgreSQLの共有メモリを増やす

KubernetesでPostgreSQLの共有メモリを増やすには以下の手順を実行します。

1. 現在の設定の確認
kubectl exec --stdin --tty ※ポッド名 --container ※コンテナ名 -- /usr/local/bin/psql -U postgres
クライアントから確認
show shared_buffers;

2. 設定変更
PVに割り当てられたディレクトリからpostgresql.confを変更
■変更前
shared_buffers = 128MB                  # min 128kB
                                        # (change requires restart)
■変更後
shared_buffers = 256MB                  # min 128kB
                                        # (change requires restart)

Documentationでは1GB以上のRAMがあればshared_buffersに対する妥当な初期値はシステムメモリの25%。
https://www.postgresql.jp/document/16/html/runtime-config-resource.html

3. 再起動して変更を反映
kubectl rollout restart deployment ※デプロイメント名

4. 再度設定確認

2024年10月17日木曜日

KubernetesでPostgreSQLをアップグレードする方法

KubernetesでPostgreSQLをアップグレードする場合、以下の順序でバージョンアップを行います。

1. 現バージョンでバックアップを取得
kubectl exec --stdin ※ポッド名 --container ※コンテナ名 -- /usr/local/bin/pg_dumpall -U postgres > dumpall.sql

2. バージョンアップ後に使用するPV/PVCを作成

3. deploymentなどで使用するPostgreSQLのイメージを新しいものに変更し、PVCもあたらしいものを参照するようにymlを更新。kubectl applyで反映。

4. 新バージョンでデータをインポート
cat dumpall.sql | kubectl exec --stdin ※ポッド名 --container ※コンテナ名 -- /usr/local/bin/psql -U postgres

5. 動作確認後、古いバージョンのPV/PVCを削除

2024年10月16日水曜日

Kubernetesでポッド内のコンテナのマウント名とパスを一覧表示する

Kubernetesでポッド内のコンテナのマウント名とパスを一覧表示するには、以下のコマンドを実行します

1.ポッド一覧を取得
kubectl get pods

2.ポッドのコンテナ内のマウント名とパスを一覧表示
kubectl get pod ※1で取得したポッド名 -o jsonpath='{range .spec.containers[*]}{.name}{"\n"}{range .volumeMounts[*]}{"- "}{.name}{":"}{.mountPath}{"\n"}{end}{end}'

2024年10月15日火曜日

Kubernetesでポッド内のコンテナ名とイメージ名を一覧表示する

Kubernetesでポッド内のコンテナ名とイメージ名を一覧表示するには、以下のコマンドを実行します
1.ポッド一覧を取得
kubectl get pods

2.コンテナ名とイメージ名を一覧表示
kubectl get pod ※1で取得したポッド名 -o jsonpath='{range .spec.containers[*]}{.name}{":"}{.image}{"\n"}{end}'

2024年8月29日木曜日

Ubuntu24.04にLangFlowをインストールする

Ubuntu24.04でpipenvを使用してLangFlowをインストールするには、以下の手順を実行します。

1.pipenvのインストール
sudo apt-get -y install python3-pip python3-dev python3-testresources pipenv 

echo "export PIPENV_VENV_IN_PROJECT=true" >> ~/.profile

source ~/.profile

2. LangFlowをインストール
mkdir ~/langflow

cd ~/langflow

pipenv install langflow

3. LangFlowをサービスとして登録
※ユーザ名・パスは適宜変更してください。
cat << EOF | sudo tee /etc/systemd/system/langflow.service
[Unit]
Description=LangFlow
[Service]
Type=simple
ExecStart=/home/ubuntu/langflow/.venv/bin/langflow run --host 0.0.0.0
User=ubuntu
Group=ubuntu
WorkingDirectory=/home/ubuntu/langflow
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
EOF

sudo systemctl enable langflow

sudo systemctl start langflow

4. ブラウザでLangFlowにアクセスします。

http://ホスト名またはIPアドレス:7860

2024年7月7日日曜日

Ubuntu24.04にllama.cppをインストールしてLlama-3-ELYZA-JP-8B-q4_k_m.ggufモデルで対話を行う

Llama.cppをインストールして、Llama-3-ELYZA-JP-8B-q4_k_m.ggufモデルでい対話するには以下のコマンドを実行します。
wget https://github.com/ggerganov/llama.cpp/releases/download/b3328/llama-b3328-bin-ubuntu-x64.zip

unzip ./llama-b3328-bin-ubuntu-x64.zip

cd ./build/bin

wget https://huggingface.co/elyza/Llama-3-ELYZA-JP-8B-GGUF/resolve/main/Llama-3-ELYZA-JP-8B-q4_k_m.gguf?download=true -O Llama-3-ELYZA-JP-8B-q4_k_m.gguf

./llama-cli -m Llama-3-ELYZA-JP-8B-q4_k_m.gguf -p "あなたは優秀なアシスタントです" -cnv
この後は対話文を入力します。対話を終了するときはCtrl+Cを押します。