ubuntu26やっと
使い始めた
。
google cloudのも
ubuntu26への塗り替えだいたい終わった。
xrdpコンテナも
ローカルubuntu26の中で使い始めたし
、次はx86のvmware環境にあるkubernetesをubuntu26ベースにバージョン上げてく。
作成イメージ#
x86ホストを用意して⭐️印箇所を作ってく。先にdocker環境をubuntu26で作ってるからインストール方法はそのメモをアレンジしてやってく。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<----------- M4 mac -----------> <--------------------- Windows11 pro VMware ---------------------> <-------- Google cloud -------->
+-macmini sequoia--------------+ +-local ubuntu26 linux ⭐️----+ +-local ubuntu26 linux--------+ +-GCE ubuntu26 linux----------+
| +-utm----------------------+ | | +-microk8s-------+ +-vmdk-+ | | +-docker---------+ +-vmdk-+ | | +-docker---------+ +--pv--+ |
| | +-sequoia-------------+ | | | | +-Pod-------+ | | data | | | | +-container-+ | | data | | | | +-container-+ | | data | |
| | | vscode/cyberduck | | | | | | Django | | | d1 | | | | | Django | | | d1 | | | | | Django | | | d1 | |
| | | office/brew/rdp | | | | | +-----------+ | +------+ | | | +-----------+ | +------+ | | | +-----------+ | +------+ |
| | +---------------------+ | | | | +-Pod-------+ | | | | | | +-container-+ | | | | | | +-container-+ | | | |
| | +-ubuntu24 x86--------+ | | | | | mariadb | | | d2 | | | | | mariadb | | | d2 | | | | | mariadb | | | d2 | |
| | | ctr microk8s | | | | | +-----------+ | +------+ | | | +-----------+ | +------+ | | | +-----------+ | +------+ |
| | |+-container-+ | | | | | +-Pod-------+ | | | | | | +-container-+ | | | | | | +-container-+ | | | |
| | ||kubernetes | | | | <- | | | xrdp-ubu26| | | d3 | | <- | | | xrdp-ubu26| | | d3 | | <- | | | xrdp-ubu24| | | d3 | |
| | |+-----------+ | | | <- | | +-----------+ | +------+ | <- | | +-----------+ | +------+ | <- | | +-----------+ | +------+ |
| | |+-container-+ +/data+| | | <- | | | | <- | | | | <- | | +-container-+ | |
| | ||Django | | d1 || | | | | | | | | | | | | | gitlab | | |
| | |+-----------+ +-----+| | | | | | | | | | | | | +-----------+ | |
| | |+-container-+ | || | | | | +-Pod-------+ | +------+ | | | +-container-+ | +------+ | | | +-container-+ | +------+ |
| | ||mariadb | | d2 || | | | | | https | | | d4 | | | | | https | | | d4 | | | | | https | | | d4 | |
| | |+-----------+ +-----+| | | | | +-----------+ | +------+ | | | +-----------+ | +------+ | | | +-----------+ | +------+ |
| | |+-container-+ | || | | | +----------------+ | | +----------------+ | | +----------------+ |
| | ||xrdp-ubu24 | | d3 || | | +-----------------------------+ +-----------------------------+ +-----------------------------+
| | |+-----------+ +-----+| | |
| | |+-container-+ +-----+| | | +--smb share ⭐️---------------+
| | ||https | | d4 || | | | windows smb share |
| | |+-----------+ +-----+| | | +-----------------------------+
| | +---------------------+ | |
| +--------------------------+ |
| |
| +-music----------+ |
| | 8400(37GB) | |
| +----------------+ |
+------------------------------+
vmware設定#
メモ
読みながら、ゲストOSの設定やってインストールしてく。
1
2
3
CPU: 6core
メモリ: 10GB
ディスク:60GB
いったんOS停止してvmwareゲストOSのvmxファイル設定をいじる。
1
2
3
mainMem.useNamedFile = "FALSE" ⭐️「ページングファイル(.vmem)」をホストのストレージ(ディスク)上に作成せん
MemTrimRate = "0" ⭐️VMwareが仮想マシンの未使用メモリをホストOSに返却する処理(メモリトリミング)を無効化
ethernet0.virtualDev = "vmxnet3" ⭐️OSインストール終わってからローカルubuntu26と同じ設定でこうする
インストールすぐ終わる。
既存のubuntu24環境と同じCPU/メモリ/ディスク/IPアドレスを割り当てて、Ubuntu26serverをほぼすっぴん状態でインストールして用意できた。
インストールでlvm広げるの忘れた#
たまにやってまうんやけど、OSインストールのときディスクのレイアウト変更忘れててlvmがディスクをめいっぱい使ってへんかった。
lvmの操作苦手なんやけどgemini先生に聞いたら、一発でディスク拡張してくれるコマンドライン教えてもらった。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
root@kubelinux:~# sudo lvdisplay ⭐️今のlvmどないなっとんねん
--- Logical volume ---
LV Path /dev/ubuntu-vg/ubuntu-lv
LV Name ubuntu-lv
VG Name ubuntu-vg
LV UUID QyTF5F-pwiE-Th1Q-Auw2-5m32-NGyv-etwOve
LV Write Access read/write
LV Creation host, time ubuntu-server, 2026-08-22 21:45:02 +0000
LV Status available
# open 1
LV Size <29.00 GiB ⭐️やってもた。60GBのうち29GBしか使ってへんしサイズ小さい。
Current LE 7423
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 16384
Block device 252:0
root@kubelinux:~# sudo lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv -r ⭐️空き領域全部使ってちょ
File system ext4 found on ubuntu-vg/ubuntu-lv mounted at /.
Size of logical volume ubuntu-vg/ubuntu-lv changed from <29.00 GiB ( 7423 extents) to <58.00 GiB ( 14847 extents) .
Extending file system ext4 to <58.00 GiB ( 62272831488 bytes) on ubuntu-vg/ubuntu-lv...
resize2fs /dev/ubuntu-vg/ubuntu-lv
resize2fs 1.47.2 ( 1-Jan-2025)
Filesystem at /dev/ubuntu-vg/ubuntu-lv is mounted on /; on-line resizing required
old_desc_blocks = 4, new_desc_blocks = 8
The filesystem on /dev/ubuntu-vg/ubuntu-lv is now 15203328 ( 4k) blocks long.
resize2fs done
Extended file system ext4 on ubuntu-vg/ubuntu-lv.
Logical volume ubuntu-vg/ubuntu-lv successfully resized. ⭐️うまいこといった
root@kubelinux:~#
root@kubelinux:~# df -hT
Filesystem Type Size Used Avail Use% Mounted on
tmpfs tmpfs 1.9G 1.5M 1.9G 1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv ext4 57G 7.2G 48G 14% / ⭐️57GBに広がった
tmpfs tmpfs 4.6G 0 4.6G 0% /dev/shm
none tmpfs 1.0M 0 1.0M 0% /run/credentials/systemd-journald.service
none tmpfs 1.0M 0 1.0M 0% /run/credentials/systemd-resolved.service
tmpfs tmpfs 4.6G 0 4.6G 0% /tmp
/dev/sda2 ext4 2.0G 188M 1.7G 11% /boot
none tmpfs 1.0M 0 1.0M 0% /run/credentials/systemd-networkd.service
none tmpfs 1.0M 0 1.0M 0% /run/credentials/getty@tty1.service
tmpfs tmpfs 939M 8.0K 939M 1% /run/user/1000
root@kubelinux:~#
仮想マシンの設定#
vmwareの起動処理を.batファイルに書いてOS起動する。
1
"C:\Program Files (x86)\VMware\VMware Workstation\vmplayer.exe" "D:\VMarea\Ubu26-kubelinux\Ubu26-kubelinux.vmx"
起動したらひっそり動き出す。
OSの状態確認やってく。24のときと同じ感じになってるか確認。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
root@kubelinux:~# ip a | grep ens32
2: ens32: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
inet 192.168.1.119/24 brd 192.168.1.255 scope global ens32 ⭐️ens32ってインターフェース名で固定IP設定できとる
root@kubelinux:~# resolvectl status ens32
Link 2 ( ens32)
Current Scopes: DNS
Protocols: +DefaultRoute -LLMNR -mDNS -DNSOverTLS DNSSEC= no/unsupported
Current DNS Server: 172.16.17.15
DNS Servers: 172.16.17.15 8.8.8.8 ⭐️宅内DNS参照できとる
Default Route: yes
root@kubelinux:~# uname -n
kubelinux ⭐️ホスト名設定できとる
root@kubelinux:~#
root@kubelinux:~# cat /etc/hosts
127.0.0.1 localhost
127.0.1.1 kubelinux ⭐️ホスト名入っとる
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
root@kubelinux:~# cat /etc/passwd | tail -3
fwupd-refresh:x:984:984:Firmware update daemon:/var/lib/fwupd:/usr/sbin/nologin
nari:x:1000:1000:nari:/home/nari:/bin/bash ⭐️インストーラで指定した一般ユーザできとる
sshd:x:983:65534:sshd user:/run/sshd:/usr/sbin/nologin
root@kubelinux:~# systemctl get-default
graphical.target ⭐️またもや・・・
root@kubelinux:~# systemctl set-default multi-user.target ⭐️multi-userに変更
Created symlink '/etc/systemd/system/default.target' → '/usr/lib/systemd/system/multi-user.target' .
root@kubelinux:~# systemd-analyze
Startup finished in 2.198s ( kernel) + 1.742s ( initrd) + 1.850s ( userspace) = 5.791s ⭐️起動にかかる時間縮んだな
multi-user.target reached after 1.847s in userspace.
root@kubelinux:~#
IPを引き継がせたら
宅内DNS
の効き目でmacから即ssh接続できる。
モジュール設定#
1
2
3
4
5
6
7
8
9
10
11
12
apt update
apt upgrade
apt autoremove
apt-get install open-vm-tools ⭐️入れとかなvmwareのシャットダウンボタンとか効かへんで
apt-get install nmon ⭐️負荷状態確認で使う
apt install vim ⭐️まだnano慣れん
apt install systemd-timesyncd ⭐️時刻同期で使う
apt install iputils-ping dnsutils traceroute ⭐️ネットワーク確認にいるで
apt install rsync ⭐️バックアップで使ってたはず
apt install logrotate ⭐️ログローテートで使う
apt install cifs-utils ⭐️smbマウントで使う
apt install snapd ⭐️microk8s利用で使う
タイムゾーン・ロケールの設定#
設定する内容のメモ。
1
2
3
4
5
6
7
8
# apt update
# apt upgrade
# timedatectl set-timezone Asia/Tokyo
# apt -y install language-pack-ja-base language-pack-ja
# localectl list-locales | grep -i ja
# localectl set-locale LANG=ja_JP.UTF-8 LANGUAGE="ja_JP:ja" ⭐️エラーになる
# update-locale LANG=ja_JP.UTF-8 LANGUAGE="ja_JP:ja" ⭐️代わりにこっち使う
# source /etc/default/locale
ローカルubuntu26を最初に設定したときはログどっかいったけど目視して設定しとく。
root@kubelinux:~# localectl set-locale LANG=ja_JP.UTF-8 LANGUAGE="ja_JP:ja"
Failed to issue method call: Locale ja_JP:ja is not valid, refusing. ⭐️エラーはこう出る
root@kubelinux:~# update-locale LANG=ja_JP.UTF-8 LANGUAGE="ja_JP:ja" ⭐️こっち使う
root@kubelinux:~# source /etc/default/locale
root@kubelinux:~# date
2026年 8月 23日 日曜日 07:43:02 JST ⭐️できた
root@kubelinux:~#
NTP設定#
時間あわせてく。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
root@kubelinux:~# timedatectl set-ntp true
root@kubelinux:~# vi /etc/systemd/timesyncd.conf ⭐️設定いじる
root@kubelinux:~# tail -3 /etc/systemd/timesyncd.conf
NTP= ntp.nict.jp ntp.mfeed.ad.jp ⭐️国内サーバ使う
FallbackNTP= ntp.ubuntu.com ⭐️もし国内サーバ使えんかったらubuntuのntp参照させる
root@kubelinux:~#
root@kubelinux:~# systemctl restart systemd-timesyncd
root@kubelinux:~# journalctl -u systemd-timesyncd -n 5 --no-pager
8月 23 07:55:13 kubelinux systemd[ 1] : Stopped systemd-timesyncd.service - Network Time Synchronization.
8月 23 07:55:13 kubelinux systemd[ 1] : Starting systemd-timesyncd.service - Network Time Synchronization...
8月 23 07:55:13 kubelinux systemd[ 1] : Started systemd-timesyncd.service - Network Time Synchronization.
8月 23 07:55:13 kubelinux systemd-timesyncd[ 19334] : Contacted time server 133.243.238.243:123 ( ntp.nict.jp) .
8月 23 07:55:13 kubelinux systemd-timesyncd[ 19334] : Initial clock synchronization to Sun 2026-08-23 07:55:13.951760 JST.
root@kubelinux:~#
.bashrc設定#
それぞれ書き足す。
/root/.bashrcに追記
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
alias dff='df -h | grep -v tmpfs | grep -v common | grep -v credentials'
alias tree="pwd;find . | sort | sed '1d;s/^\.//;s/\/\([^/]*\)$/|--/;s/\/[^/|]*/| /g'"
alias sc='cd /microk8s/script'
alias m8='cd /microk8s'
alias dc='cd /data'
alias kubectl='microk8s kubectl'
## 配下の.DS_Storeと._xxx を削除
function removegomi () {
find . \( -name '.DS_Store' -or -name '._*' \) -delete -print;
}
alias rmgomi=removegomi
PATH=/microk8s/script:$PATH:$HOME/bin
export PATH
/home/nari/.bashrcに追記
1
2
3
4
5
6
7
8
9
10
11
12
13
14
alias dff='df -h | grep -v tmpfs | grep -v common | grep -v credentials'
alias tree="pwd;find . | sort | sed '1d;s/^\.//;s/\/\([^/]*\)$/|--/;s/\/[^/|]*/| /g'"
alias sc='cd /microk8s/script'
alias m8='cd /microk8s'
alias dc='cd /data'
## 配下の.DS_Storeと._xxx を削除
function removegomi () {
find . \( -name '.DS_Store' -or -name '._*' \) -delete -print;
}
alias rmgomi=removegomi
PATH=/microk8s/script:$PATH:$HOME/bin
export PATH
smb共有フォルダ使う#
windowsホスト母艦にしてて、その中にkubernetesの領域用意してる。
ubuntu26側でmkdir /microk8sした領域にsmbマウントしてく。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
root@kubelinux:~# mkdir /microk8s ⭐️マウントポイント作る
root@kubelinux:~# vi /etc/systemd/system/gvis-smb-folders.service ⭐️定義作る
root@kubelinux:~# cat /etc/systemd/system/gvis-smb-folders.service
[ Unit]
Description= gvis Shared Folders Mount
[ Service]
Type= forking
## ExecStart=mount -t cifs -o username=nari,password=xxxx //192.168.1.40/kubernetes /microk8s ⭐️ubuntu24で使えてたのがアカンかった
ExecStart= mount -t cifs -o username= nari,password= 'xxxx' ,domain= WORKGROUP //192.168.1.40/kubernetes /microk8s ⭐️こう書くらしい
[ Install]
WantedBy= multi-user.target
root@kubelinux:~# systemctl daemon-reload ⭐️サービス定義をデーモンとして認識させる
root@kubelinux:~# systemctl enable gvis-smb-folders.service ⭐️サービス有効化してOS起動したらsmb接続する
Created symlink '/etc/systemd/system/multi-user.target.wants/gvis-smb-folders.service' → '/etc/systemd/system/gvis-smb-folders.service' .
root@kubelinux:~# systemctl status gvis-smb-folders.service
○ gvis-smb-folders.service - gvis Shared Folders Mount
Loaded: loaded ( /etc/systemd/system/gvis-smb-folders.service; enabled; preset: enabled)
Active: inactive ( dead)
root@kubelinux:~#
smbでマウントしようとしたら、最初は接続うまくいかんかったな。少し切り分けしてからgemini先生に相談した。
■相談
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
mountは失敗するが、smbclientはうまくいく。なぜか。
root@kubelinux:~# mount -t cifs -o username=shanshan-64\\nari,password='xxxx' //192.168.1.40/kubernetes /microk8s
mount error(13): Permission denied
Refer to the mount.cifs(8) manual page (e.g. man mount.cifs) and kernel log messages (dmesg)
root@kubelinux:~# smbclient //192.168.1.40/kubernetes -U nari
Password for [WORKGROUP\nari]:xxxx
Try "help" to get a list of possible commands.
smb: \>
相変わらず返答速い。
■回答
1
2
3
4
5
6
7
8
9
10
11
smbclient(ユーザー空間のアプリ)と mount -t cifs(Linux カーネル)では、
Windows 側へ送信する認証情報の形式(ドメイン名・ネゴシエーション方式)の扱いが異なるためです。
smbclient のログを見ると WORKGROUP\nari として認証が通っていますが、
mount 実行時は shanshan-64\nari やバックスラッシュ(\)のエスケープ処理により、
Windows 側で想定外のドメイン名として解釈され拒否されています。
:(中略)
方法1: ドメインに WORKGROUP を明示指定する(推奨)
:(中略)
方法2: バックスラッシュをシングルクォートで完全に囲む
:(中略)
何度か接続失敗したら認証がロックされてまうことあるからwindows側でこのへん使う。
net user nari /active:yes
net user nari /expires:never
net user nari /passwordchg:no
書いてる内容のうち、mount -t cifs〜はgemini先生のアドバイスにあった2つの方法を混ぜて指定入れたらつながった。
1
2
3
4
[ Service]
Type= forking
## ExecStart=mount -t cifs -o username=nari,password=xxxxxx //192.168.1.40/kubernetes /microk8s ⭐️これではアカン
ExecStart= mount -t cifs -o username= nari,password= 'xxxxxx' ,domain= WORKGROUP //192.168.1.40/kubernetes /microk8s ⭐️こう書く
つながったらこうなる。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
root@kubelinux:~# ls -l /microk8s
total 36
-rwxr-xr-x 1 root root 809 Dec 24 2024 cl-ubun-pod.yaml
-rwxr-xr-x 1 root root 1361 Dec 22 2024 gvis-PersistentVol-mariadb.yaml
-rwxr-xr-x 1 root root 1393 Dec 22 2024 gvis-PersistentVol-mariadbconf.yaml
-rwxr-xr-x 1 root root 1405 Dec 22 2024 gvis-PersistentVol-sv_django-ssl_certs.yaml
-rwxr-xr-x 1 root root 1414 Dec 22 2024 gvis-PersistentVol-sv_django-uwsgi-nginx.yaml
-rwxr-xr-x 1 root root 1352 Dec 22 2024 gvis-PersistentVol-ubun.yaml
-rwxr-xr-x 1 root root 12 Dec 22 2024 kubernetes.txt
drwxr-xr-x 2 root root 0 Aug 23 06:08 log
-rwxr-xr-x 1 root root 280 Dec 22 2024 mariadb-txt-configmap.yaml
drwxr-xr-x 2 root root 0 Jul 4 06:01 nariDockerDat
drwxr-xr-x 2 root root 0 Jun 14 03:51 script
-rwxr-xr-x 1 root root 839 Dec 24 2024 sv-django-pod.yaml
-rwxr-xr-x 1 root root 211 Dec 22 2024 sv-django-service.yaml
-rwxr-xr-x 1 root root 1003 Dec 24 2024 sv-https-portal-pod.yaml
-rwxr-xr-x 1 root root 287 Dec 22 2024 sv-https-portal-service.yaml
-rwxr-xr-x 1 root root 1899 Dec 24 2024 sv-mariadb-pod.yaml
-rwxr-xr-x 1 root root 214 Dec 22 2024 sv-mariadb-service.yaml
drwxr-xr-x 2 root root 0 Mar 4 2025 共有設定
root@kubelinux:~#
scriptのフォルダあるから、クラスタ操作する運用スクリプトが使える。
1
2
3
4
5
6
root@kubelinux:~# dff
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/ubuntu--vg-ubuntu--lv 57G 7.0G 48G 13% /
/dev/sda2 2.0G 96M 1.7G 6% /boot
//192.168.1.40/kubernetes 932G 377G 556G 41% /microk8s ⭐️OS再起動してマウントできとる
root@kubelinux:~#
クラスタ作成#
kubernetesのクラスタバージョン確認する。
Kubernetes | endoflife.date
運用スクリプト
にバージョン指定する。
今回はちょっと手間かかった。
Dashboard使うのやめて次のを選ぶ#
Dashboard使おうとしたら、アドオンが非推奨になったらしく、無理して使わんことにした。
■相談
1
2
3
4
5
6
7
8
9
10
11
12
Dashboardがまだ有効にならない。
root@kubelinux:/microk8s/script# microk8s addons repo update community
Updating repository community
Already up to date.
root@kubelinux:/microk8s/script# microk8s status
microk8s is running
:(中略)
■回答
1
2
MicroK8s v1.36の公式・コミュニティリポジトリの双方から dashboard アドオン自体が
非推奨・削除されている状態です(代わりに portainer や observability などが一覧に入っています)。
なんですと!! 非推奨なっとるやんけ。
別のを使うようになってきてるらしいな。どれがええんかgemini先生に相談してみよか。
■相談
1
2
3
4
ローカルPCのvmwareのゲストOSとしてubuntu26を稼働させていて、
その中でmicrok8sでkubernetesクラスタを起動させている。
PortainerとHeadlampのどちらを使うのがいいか。
できるだけ軽量で使い続けられるものがいいが、選択の根拠を示して。
■回答
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
今回の利用環境(VMware上のUbuntu 26 VM + MicroK8s)において、「軽量さ」 と 「長期的・持続的な使いやすさ(メンテナンス性)」 を最優先にする場合、結論として Headlamp を選ぶのが最適です。
1. リソース消費の小ささ(軽量性)
:(中略)
2. アーキテクチャのシンプルさ(直感性)
:(中略)
3. コミュニティの推奨度と将来性(エコシステム)
:(中略)
Headlamp を選ぶべきケース(今回のおすすめ)
・VMのリソース消費を極力抑えたい ⭐️今はここに軸を置く
・kubectl や公式ダッシュボードと同じ感覚でPodやログを素早く確認したい
・Kubernetesの標準仕様に沿って学習・運用を進めたい
Portainer を選ぶべきケース
・将来的にDockerスタンドアロン環境や複数のKubernetesクラスタを
1つの画面でまとめて管理したい場合 ⭐️今はそんなんいらん
:(中略)
vmwareのゲストOSのリソースの都合あるから
Headlamp
を選ぶかな。
Headlamp使い始め#
gemini先生に相談してクラスタ作るスクリプトでHeadlamp有効にするように書き換えてもらった。
Helm使ってるみたいやけど、大きな問題なさそうやな。
/gvis/script/300_kubeClusterRecreate.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
## -------------------------------------------------------------------------
## Script Name : 300_kubeClusterRecreate.sh
## Created by : T.Naritomi
## on : 2023.08.26
## Updated by : 2026.08.24
## on :
## Parameters :
## Return Code : 0=Normal End
## Comments : change driver hyperkit -> qemu2 , minikube -> microk8s
## -------------------------------------------------------------------------
## ---define----------------------------------------------------------------
EXEC_HOME=/microk8s/script # Execute Home directory
KUBE_HOME=/microk8s # kubernetes Home directory
LOG_FILE=/microk8s/log/kube.log # Log file
GVIS_VER=1.36/stable
GVIS_USER=nari
## ---detail----------------------------------------------------------------
read -p "--- kube Data save ready ? ---(y/N):" yn
case "$yn" in [yY]*) ;; *) echo "abort." ; exit ;; esac
read -p "--- kube Recreate cluster ready ? ---(y/N):" yn
case "$yn" in [yY]*) ;; *) echo "abort." ; exit ;; esac
echo '---Recreate start---' >> ${LOG_FILE}
echo -------- `date +%F_%T` -------- >> ${LOG_FILE}
echo ${LOG_FILE}
snap remove microk8s >> ${LOG_FILE}
rm -fR ~/.kube
echo -------- `date +%F_%T` -------- >> ${LOG_FILE}
snap install microk8s --channel=${GVIS_VER} --classic >> ${LOG_FILE}
mkdir -p /data
chmod 777 /data
# ----- 既存の有効化アドオン -----
microk8s enable registry --size 30Gi >> ${LOG_FILE}
microk8s enable hostpath-storage >> ${LOG_FILE}
microk8s enable host-access >> ${LOG_FILE}
# ----- Headlamp用の追加設定 ----- ⭐️こっからgemini先生に書いてもらった
# 1. Helmを有効化
microk8s enable helm3 >> ${LOG_FILE}
# MicroK8sのAPI準備完了を待機
microk8s status --wait-ready >> ${LOG_FILE}
# 2. Headlampのインストール
microk8s helm repo add headlamp https://kubernetes-sigs.github.io/headlamp/ >> ${LOG_FILE}
microk8s helm repo update >> ${LOG_FILE}
microk8s helm install headlamp headlamp/headlamp --namespace kube-system >> ${LOG_FILE}
# 3. Headlamp管理者用アカウント(ServiceAccount)の作成
microk8s kubectl apply -f - <<EOF >> ${LOG_FILE}
apiVersion: v1
kind: ServiceAccount
metadata:
name: headlamp-admin
namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: headlamp-admin
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: headlamp-admin
namespace: kube-system
EOF
# 4. アクセストークンの発行とログ出力
echo "=== Headlamp Login Token ===" | tee -a ${LOG_FILE}
microk8s kubectl create token headlamp-admin -n kube-system | tee -a ${LOG_FILE} ⭐️後で出力拾っとこ
echo "============================" | tee -a ${LOG_FILE}
echo -------- kubernetes cluster created -------- >> ${LOG_FILE} ⭐️ここまでgemini先生に作ってもらった
sync ; sync ; sync
sleep 10
microk8s kubectl apply -f ${KUBE_HOME}/gvis-PersistentVol-mariadb.yaml
microk8s kubectl apply -f ${KUBE_HOME}/gvis-PersistentVol-mariadbconf.yaml
microk8s kubectl apply -f ${KUBE_HOME}/gvis-PersistentVol-sv_django-ssl_certs.yaml
microk8s kubectl apply -f ${KUBE_HOME}/gvis-PersistentVol-sv_django-uwsgi-nginx.yaml
microk8s kubectl apply -f ${KUBE_HOME}/gvis-PersistentVol-ubun.yaml
microk8s kubectl apply -f ${KUBE_HOME}/mariadb-txt-configmap.yaml
microk8s kubectl apply -f ${KUBE_HOME}/sv-django-service.yaml
microk8s kubectl apply -f ${KUBE_HOME}/sv-https-portal-service.yaml
microk8s kubectl apply -f ${KUBE_HOME}/sv-mariadb-service.yaml
echo -------- `date +%F_%T` -------- >> ${LOG_FILE}
sleep 10 ⭐️自分でここ追加。これないとポート転送できん
microk8s kubectl get nodes
microk8s kubectl port-forward -n kube-system service/headlamp 18080:80 --address 0.0.0.0 &
exit $?
ブラウザで開く#
2026年8月は1.36/stableやな。時期的にそろそろ次の出そうやな。過去ログを日付でプレフィスクつけて退避しておいてからクラスタ作る。
root@kubelinux:/microk8s/script# ls ../log
20241204kube.log 20250507kube.log 20250904kube.log 20260823kube.log
20241223kube.log 20250516kube.log 20260517kube.log
root@kubelinux:/microk8s/script# sh ./300_kubeClusterRecreate.sh ⭐️クラスタ作ってちょ
--- kube Data save ready ? ---(y/N):y
--- kube Recreate cluster ready ? ---(y/N):y
/microk8s/log/kube.log
error: lost connection to pod
Infer repository core for addon registry
Infer repository core for addon hostpath-storage
Infer repository core for addon hostpath-storage
Infer repository core for addon host-access
Error: ipv4: Address already assigned. ⭐️何回か作り直したからこうなるんかなぁ
Infer repository core for addon helm3
Warning: resource clusterrolebindings/headlamp-admin is missing the kubectl.kubernetes.io/last-applied-configuration annotation which is required by kubectl apply. kubectl apply should only be used on resources created declaratively by either kubectl create --save-config or kubectl apply. The missing annotation will be patched automatically.
=== Headlamp Login Token ===
:(中略)
============================
persistentvolume/gvis-pv-mariadb created
persistentvolumeclaim/gvis-pv-mariadb-claim created
persistentvolume/gvis-pv-mariadbconf created
persistentvolumeclaim/gvis-pv-mariadbconf-claim created
persistentvolume/gvis-pv-django-sslcerts created
persistentvolumeclaim/gvis-pv-django-sslcerts-claim created
persistentvolume/gvis-pv-django-uwsgi-nginx created
persistentvolumeclaim/gvis-pv-django-uwsgi-nginx-claim created
persistentvolume/gvis-pv-ubun created
persistentvolumeclaim/gvis-pv-ubun-claim created
configmap/sv-mariadb-txt created
service/sv-django created
service/sv-https-portal created
service/sv-mariadb created
NAME STATUS ROLES AGE VERSION
kubelinux Ready <none> 36s v1.36.2
root@kubelinux:/microk8s/script# Forwarding from 0.0.0.0:18080 -> 4466 ⭐️ポートフォワードできたんとちゃうか
root@kubelinux:/microk8s/script#
ログ見てもなんとなくコントロールプレーンできとる。
root@kubelinux:/microk8s/log# cat kube.log
---Recreate start---
-------- 2026-08-24_05:53:38 --------
microk8s removed (snap data snapshot saved)
-------- 2026-08-24_05:54:00 --------
microk8s (1.36/stable) v1.36.2 from Canonical** installed
Enabling default storage class.
WARNING: Hostpath storage is not suitable for production environments.
A hostpath volume can grow beyond the size limit set in the volume claim manifest.
deployment.apps/hostpath-provisioner created
storageclass.storage.k8s.io/microk8s-hostpath created
serviceaccount/microk8s-hostpath created
clusterrole.rbac.authorization.k8s.io/microk8s-hostpath created
clusterrolebinding.rbac.authorization.k8s.io/microk8s-hostpath created
Storage will be available soon.
namespace/container-registry created
persistentvolumeclaim/registry-claim created
deployment.apps/registry created
service/registry created
configmap/local-registry-hosting configured
The registry will be created with the size of 30Gi.
Default storage class will be used.
Addon core/hostpath-storage is already enabled
Setting 10.0.1.1 as host-access
Addon core/helm3 is already enabled
microk8s is running ⭐️動いたな
high-availability: no
datastore master nodes: 127.0.0.1:19001
datastore standby nodes: none
addons:
enabled:
dns # (core) CoreDNS
ha-cluster # (core) Configure high availability on the current node
helm # (core) Helm - the package manager for Kubernetes
helm3 # (core) Helm 3 - the package manager for Kubernetes
host-access # (core) Allow Pods connecting to Host services smoothly
hostpath-storage # (core) Storage class; allocates storage from host directory
registry # (core) Private image registry exposed on localhost:32000
storage # (core) Alias to hostpath-storage add-on, deprecated
disabled:
cert-manager # (core) Cloud native certificate management
cis-hardening # (core) Apply CIS K8s hardening
community # (core) The community addons repository
gpu # (core) Alias to nvidia add-on
ingress # (core) Ingress controller for external access
kube-ovn # (core) An advanced network fabric for Kubernetes
mayastor # (core) OpenEBS MayaStor
metallb # (core) Loadbalancer for your Kubernetes cluster
metrics-server # (core) K8s Metrics Server for API access to service metrics
minio # (core) MinIO object storage (DEPRECATED). This addon is deprecated and will be completely removed in the upcoming versions
nvidia # (core) NVIDIA hardware (GPU and network) support
observability # (core) A lightweight observability stack for logs, traces and metrics
prometheus # (core) Prometheus operator for monitoring and logging
rbac # (core) Role-Based Access Control for authorisation
rook-ceph # (core) Distributed Ceph storage using Rook
"headlamp" already exists with the same configuration, skipping
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "headlamp" chart repository ⭐️Headlampもいけとる
Update Complete. ⎈Happy Helming!⎈
NAME: headlamp
LAST DEPLOYED: Mon Aug 24 05:54:34 2026
NAMESPACE: kube-system
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
1. Get the application URL by running these commands:
export POD_NAME=$(kubectl get pods --namespace kube-system -l "app.kubernetes.io/name=headlamp,app.kubernetes.io/instance=headlamp" -o jsonpath="{.items[0].metadata.name}")
export CONTAINER_PORT=$(kubectl get pod --namespace kube-system $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl --namespace kube-system port-forward $POD_NAME 8080:$CONTAINER_PORT
2. Get the token using
kubectl create token headlamp --namespace kube-system
serviceaccount/headlamp-admin created
clusterrolebinding.rbac.authorization.k8s.io/headlamp-admin configured
=== Headlamp Login Token ===
:(中略)
============================
-------- kubernetes cluster created --------
-------- 2026-08-24_05:54:45 --------
クラスタ作ったらブラウザでコンソールにトークン入力してログインしてみる。
こんな画面なんやな。応答良くてスイスイ動いてくれるし軽い。Dashboardに代わって使わせてもらうで。
クラスタ起動できてサービスのマニフェストも入ったな。
1
2
3
4
5
6
7
8
9
10
11
12
root@kubelinux:/microk8s/script# alias | grep kube
alias kubectl= 'microk8s kubectl'
root@kubelinux:/microk8s/script# kubectl get nodes,services
NAME STATUS ROLES AGE VERSION
node/kubelinux Ready <none> 16m v1.36.2
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT( S) AGE
service/kubernetes ClusterIP 10.152.183.1 <none> 443/TCP 16m
service/sv-django ClusterIP 10.152.183.215 <none> 38080/TCP 16m
service/sv-https-portal ClusterIP 10.152.183.167 <none> 30080/TCP,30443/TCP 16m
service/sv-mariadb ClusterIP 10.152.183.246 <none> 13306/TCP 16m
root@kubelinux:/microk8s/script#
dockerイメージをインポート#
teratermマクロ少し書き換えてdockerイメージの元ファイルをx86のkubernetes環境へscpコピーさせてからgunzipさせる。
nari@kubelinux:~$ sudo su -
[sudo: authenticate] パスワード:
root@kubelinux:~# rm -f /microk8s/nariDockerDat/DockerImages/save*
root@kubelinux:~# ps -ef |grep -v grep |grep -c scp
2
root@kubelinux:~#
root@kubelinux:~# ps -ef |grep -v grep |grep -c scp ⭐️teratermマクロでscp終わるの待つ
0
root@kubelinux:~# echo SCP finish
SCP finish
cd /microk8s/nariDockerDat/DockerImages
root@kubelinux:~# cd /microk8s/nariDockerDat/DockerImages
mv /tmp/save* ./
root@kubelinux:/microk8s/nariDockerDat/DockerImages# mv /tmp/save* ./
gunzip save-xrdpubu.tar.gz
root@kubelinux:/microk8s/nariDockerDat/DockerImages# gunzip save-xrdpubu.tar.gz
gunzip save-django.tar.gz
root@kubelinux:/microk8s/nariDockerDat/DockerImages# gunzip save-django.tar.gz
root@kubelinux:/microk8s/nariDockerDat/DockerImages#
今回はdockerイメージのインポートがストレートに行かんかった。
root@kubelinux:/microk8s/nariDockerDat/DockerImages# microk8s.ctr images rm docker.io/library/save-django:gvis-saved
docker.io/library/save-django:gvis-saved
root@kubelinux:/microk8s/nariDockerDat/DockerImages# microk8s.ctr images import save-djang
o.tar
docker.io/library/save django:gvis saved saved
application/vnd.oci.image.manifest.v1+json sha256:a0347ec5231b16114e3a21317d2fdf9c16a8aae4d84a99d7ee4fae23d8f63e3a
Importing elapsed: 8.0 s total: 0.0 B (0.0 B/s) ⭐️なんでゼロバイトやねん
root@kubelinux:/microk8s/nariDockerDat/DockerImages#
gemini先生に相談したら、「microk8s(ラッパーコマンド群)と microk8s.ctr(containerd 直接操作ツール)は、操作する対象のレイヤー(ネームスペースや目的)が異なります。」って教えてくれた。
Kubernetes(k8s)からそのイメージが見えるかどうか(デフォルトのネームスペースの違い)があるらしいので、.ctrを外してみろって教えてもらった。
root@kubelinux:~# cd /data
root@kubelinux:/data# rm -fR gvis-pv-ubun ; sync ; cp /microk8s/nariDockerDat/gvis-pv-ubun.tar.gz /data ; tar xzf gvis-pv-ubun.tar.gz
root@kubelinux:/data# chown -R nari:nari gvis-pv-ubun ; chmod -R 777 gvis-pv-ubun ; sync
root@kubelinux:/data# cd /microk8s/nariDockerDat/DockerImages
root@kubelinux:/microk8s/nariDockerDat/DockerImages# microk8s.ctr images rm docker.io/library/save-django:gvis-saved
docker.io/library/save-django:gvis-saved
root@kubelinux:/microk8s/nariDockerDat/DockerImages# microk8s.ctr images rm docker.io/library/save-xrdpubu:gvis-saved
docker.io/library/save-xrdpubu:gvis-saved
root@kubelinux:/microk8s/nariDockerDat/DockerImages# microk8s images import save-django.tar ⭐️.ctrって外す
Pushing OCI images to 192.168.1.119:25000
root@kubelinux:/microk8s/nariDockerDat/DockerImages# microk8s images import save-xrdpubu.tar ⭐️.ctrって外す
Pushing OCI images to 192.168.1.119:25000
root@kubelinux:/microk8s/nariDockerDat/DockerImages# microk8s.ctr images ls | grep save ⭐️おお、インポートできとる
docker.io/library/save-django:gvis-saved application/vnd.oci.image.manifest.v1+json sha256:a0347ec5231b16114e3a21317d2fdf9c16a8aae4d84a99d7ee4fae23d8f63e3a 1.4 GiB linux/amd64 io.cri-containerd.image=managed
docker.io/library/save-xrdpubu:gvis-saved application/vnd.oci.image.manifest.v1+json sha256:5a4ea67fb2b4f5fe1fe1e312caf1ab85a4d011cab14be0df38523dc1ff0486d5 7.3 GiB linux/amd64 io.cri-containerd.image=managed
root@kubelinux:/microk8s/nariDockerDat/DockerImages#
イメージのサイズがゼロやなくて想定サイズになっとったらOK。
永続化領域をコピー#
mariadbとdjangoのデータな。teratermマクロがんばれー。
mariadbのデータ流し込み#
maridbのデータコピーしとく。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
nari@kubelinux:~$ sudo su -
[ sudo: authenticate] パスワード:
root@kubelinux:~# rm -f /tmp/*.sql ; rm -f /tmp/gvis.cnf
root@kubelinux:~# ps -ef |grep -v grep |grep -c scp
2
root@kubelinux:~#
root@kubelinux:~# ps -ef |grep -v grep |grep -c scp
0
root@kubelinux:~# echo SCP finish
m8
SCP finish
root@kubelinux:~# m8
root@kubelinux:/microk8s# kubectl delete -f sv-mariadb-pod.yaml
kubectl delete -f gvis-PersistentVol-mariadbconf.yaml
Error from server ( NotFound) : error when deleting "sv-mariadb-pod.yaml" : pods "sv-mariadb" not found
root@kubelinux:/microk8s# kubectl delete -f gvis-PersistentVol-mariadbconf.yaml
kubectl delete -f gvis-PersistentVol-mariadb.yaml
persistentvolume "gvis-pv-mariadbconf" deleted
persistentvolumeclaim "gvis-pv-mariadbconf-claim" deleted from default namespace
root@kubelinux:/microk8s# kubectl delete -f gvis-PersistentVol-mariadb.yaml
persistentvolume "gvis-pv-mariadb" deleted
persistentvolumeclaim "gvis-pv-mariadb-claim" deleted from default namespace
root@kubelinux:/microk8s# cd /data
root@kubelinux:/data# rm -fR ./gvis-pv-mariadb ; rm -fR ./gvis-pv-mariadbconf ; sync ; sync
root@kubelinux:/data# mkdir -p /data/gvis-pv-mariadbconf/nari/fullback/ ; mkdir -p gvis-pv-mariadb
root@kubelinux:/data# cd /microk8s/nariDockerDat/
root@kubelinux:/microk8s/nariDockerDat# cp -p /tmp/gvis.cnf /microk8s/nariDockerDat/sv_mariadb11conf/
root@kubelinux:/microk8s/nariDockerDat# mv /tmp/gvis.cnf /data/gvis-pv-mariadbconf/
root@kubelinux:/microk8s/nariDockerDat# cp -p ./sv_mariadb11conf/nari/fullback/2_fullRecover.sh /data/gvis-pv-mariadbconf/nari/fullback/
root@kubelinux:/microk8s/nariDockerDat# cp -p ./sv_mariadb11conf/nari/fullback/4_nariDB_DjangoRecover.sh /data/gvis-pv-mariadbconf/nari/fullback/
root@kubelinux:/microk8s/nariDockerDat# mv /tmp/FullBackup_nariDB_1st.sql /data/gvis-pv-mariadbconf/nari/
root@kubelinux:/microk8s/nariDockerDat# mv /tmp/FullBackup_nariDB_Django.sql /data/gvis-pv-mariadbconf/nari/
root@kubelinux:/microk8s/nariDockerDat# cd /data
root@kubelinux:/data# chmod -R 777 gvis-pv-mariadbconf
root@kubelinux:/data# chmod -R 777 gvis-pv-mariadb
root@kubelinux:/data# chmod 644 /data/gvis-pv-mariadbconf/gvis.cnf
root@kubelinux:/data# m8
root@kubelinux:/microk8s# kubectl create -f gvis-PersistentVol-mariadbconf.yaml
persistentvolume/gvis-pv-mariadbconf created
persistentvolumeclaim/gvis-pv-mariadbconf-claim created
root@kubelinux:/microk8s# kubectl create -f gvis-PersistentVol-mariadb.yaml
persistentvolume/gvis-pv-mariadb created
persistentvolumeclaim/gvis-pv-mariadb-claim created
root@kubelinux:/microk8s# kubectl create -f sv-mariadb-pod.yaml
pod/sv-mariadb created
root@kubelinux:/microk8s# sync ; sync ; sleep 30 ⭐️少し待たせる
コピーしたらデータベースをロードする。
次後半行くで。Podにログインしてデータをロードしてく。
root@kubelinux:/microk8s# kubectl exec -it `kubectl get pod | grep mariadb | awk '{print $1}'` -- bash
root@svmariadb:/# sync ; sleep 20 ; sync
root@svmariadb:/# /bin/sh /etc/mysql/conf.d/nari/fullback/2_fullRecover.sh ⭐️本番データのロード
root@svmariadb:/# sync ; sleep 20 ; sync
root@svmariadb:/# /bin/sh /etc/mysql/conf.d/nari/fullback/4_nariDB_DjangoRecover.sh ⭐️使わんけどテスト環境データのロード
root@svmariadb:/# sync ; sleep 20 ; sync
root@svmariadb:/# mariadb -unari -pXXXXXXXXXXXXXX
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 5
Server version: 11.4.13-MariaDB-ubu2404-log mariadb.org binary distribution
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> show variables like 'max_allowed_packet' ;
+--------------------+------------+
| Variable_name | Value |
+--------------------+------------+
| max_allowed_packet | 1073741824 | ⭐️mariadbの設定ファイル(/etc/mysql/conf.dへマウントした内容)が反映できとる
+--------------------+------------+
1 row in set (0.001 sec)
MariaDB [(none)]> show databases ;
+--------------------+
| Database |
+--------------------+
| information_schema |
| nariDB_1st | ⭐️ロードできとる
| nariDB_Django | ⭐️ロードできとる
+--------------------+
3 rows in set (0.000 sec)
MariaDB [(none)]> use nariDB_1st ;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
select count(*) from GVIS_keihi ;
Database changed
MariaDB [nariDB_1st]> select count(*) from GVIS_keihi ;
+----------+
| count(*) |
+----------+
| 13378 | ⭐️レコード入っとる
+----------+
1 row in set (0.001 sec)
MariaDB [nariDB_1st]> exit
Bye
root@svmariadb:/# exit
exit
root@kubelinux:/microk8s# rm -f /data/gvis-pv-mariadbconf/nari/FullBackup_nariDB_1st.sql
root@kubelinux:/microk8s# rm -f /data/gvis-pv-mariadbconf/nari/FullBackup_nariDB_Django.sql
root@kubelinux:/microk8s#
コマンドライン結果は長いけどteratermマクロで動くのは一瞬。楽ですなぁ。
djangoのデータ流し込み#
djangoのアプリケーションコンテナもちゃんと流し込む。docker環境で6にバージョン上げたけど動いてくれるやろか。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
nari@kubelinux:~$ sudo su -
[ sudo: authenticate] パスワード:
root@kubelinux:~# rm -f /tmp/sv_django-uwsgi-nginx.tar.gz
root@kubelinux:~# ps -ef |grep -v grep |grep -c scp
0
echo SCP finish
root@kubelinux:~# echo SCP finish
SCP finish
root@kubelinux:~# cd /microk8s/nariDockerDat ; rm -f sv_django-uwsgi-nginx.tar.gz ; mv /tmp/sv_django-uwsgi-nginx.tar.gz ./
rm -fR ./sv_django-uwsgi-nginx
root@kubelinux:/microk8s/nariDockerDat# rm -fR ./sv_django-uwsgi-nginx
root@kubelinux:/microk8s/nariDockerDat# m8
kubectl delete -f sv-django-pod.yaml
root@kubelinux:/microk8s# kubectl delete -f sv-django-pod.yaml
kubectl delete -f gvis-PersistentVol-sv_django-uwsgi-nginx.yaml
Error from server ( NotFound) : error when deleting "sv-django-pod.yaml" : pods "sv-django" not found ⭐️初回はエラーでええ
root@kubelinux:/microk8s# kubectl delete -f gvis-PersistentVol-sv_django-uwsgi-nginx.yaml
persistentvolume "gvis-pv-django-uwsgi-nginx" deleted
persistentvolumeclaim "gvis-pv-django-uwsgi-nginx-claim" deleted from default namespace
root@kubelinux:/microk8s# cd /data
root@kubelinux:/data# rm -fR ./gvis-pv-django-uwsgi-nginx ; rm -fR ./gvis-pv-django-sslcerts ; sync
root@kubelinux:/data# cp -p /microk8s/nariDockerDat/sv_django-uwsgi-nginx.tar.gz ./
root@kubelinux:/data# tar xzf sv_django-uwsgi-nginx.tar.gz ⭐️展開してちょ
root@kubelinux:/data# mv ./sv_django-uwsgi-nginx/app ./gvis-pv-django-uwsgi-nginx ; mkdir gvis-pv-django-sslcerts
root@kubelinux:/data# /bin/sh /data/sv_django-uwsgi-nginx/kubelinuxCopy.sh ⭐️cssとかをx86用のkubernetes環境ので上書きコピーしてちょ
root@kubelinux:/data# chmod 777 gvis-pv-django-uwsgi-nginx ; chmod 777 gvis-pv-django-sslcerts
root@kubelinux:/data# rm -fR ./sv_django-uwsgi-nginx/
root@kubelinux:/data# m8
root@kubelinux:/microk8s# kubectl create -f gvis-PersistentVol-sv_django-uwsgi-nginx.yaml ⭐️がんばれー
persistentvolume/gvis-pv-django-uwsgi-nginx created
persistentvolumeclaim/gvis-pv-django-uwsgi-nginx-claim created
root@kubelinux:/microk8s# kubectl create -f sv-django-pod.yaml
pod/sv-django created
root@kubelinux:/microk8s# sleep 10
root@kubelinux:/microk8s# kubectl exec -it ` kubectl get pod | grep sv-django | awk '{print $1}' ` -- bash ⭐️Podにログインしてちょ
bash: warning: setlocale: LC_ALL: cannot change locale ( en_US.UTF-8)
root@sv-django:/# pip3 list -o ⭐️未更新のモジュールどれぐらいあるねん
Package Version Latest Type
-------- ------- ------ -----
numpy 2.5.1 2.5.2 wheel
sqlparse 0.5.5 0.6.0 wheel
wheel 0.47.0 0.48.0 wheel
root@sv-django:/# exit
exit
root@kubelinux:/microk8s# sc
root@kubelinux:/microk8s/script# sh ./415_ReCreateHTTPSpod.sh ⭐️httpsも動いてちょ
NAME READY STATUS RESTARTS AGE
sv-django 1/1 Running 0 15s
sv-mariadb 1/1 Running 0 10m
Error from server ( NotFound) : error when deleting "/microk8s/sv-https-portal-pod.yaml" : pods "sv-https-portal" not found
pod/sv-https-portal created
NAME READY STATUS RESTARTS AGE
sv-django 1/1 Running 0 15s
sv-https-portal 0/1 ContainerCreating 0 0s
sv-mariadb 1/1 Running 0 10m
root@kubelinux:/microk8s/script#
ちょっとしたら動作が落ち着いでPodの状態がRunningになってく。
xrdpのPod起動する#
インポートしたdockerイメージはサイズ大きいけど、すぐ動く。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
root@kubelinux:/microk8s/script# cat 413_ReCreateXRDPpod.sh
#!/bin/sh
## -------------------------------------------------------------------------
## Script Name : 413_ReCreateXRDPpod.sh
## Created by : T.Naritomi
## on : 2024.12.24
## Updated by :
## on :
## Parameters :
## Return Code : 0=Normal End
## Comments : minikube -> microk8s
## -------------------------------------------------------------------------
KB_HOME= /microk8s
## ---detail----------------------------------------------------------------
microk8s kubectl get pod
microk8s kubectl delete -f ${ KB_HOME} /cl-ubun-pod.yaml
microk8s kubectl apply -f ${ KB_HOME} /cl-ubun-pod.yaml
## sleep 10
## kubectl port-forward --address 0.0.0.0 `kubectl get pod | grep cl-ubun | awk '{print $1}'` 33389:3389 &
microk8s kubectl get pod
exit
root@kubelinux:/microk8s/script# sh ./413_ReCreateXRDPpod.sh
NAME READY STATUS RESTARTS AGE
sv-django 1/1 Running 0 7m35s
sv-https-portal 1/1 Running 0 7m20s
sv-mariadb 1/1 Running 0 18m
Error from server ( NotFound) : error when deleting "/microk8s/cl-ubun-pod.yaml" : pods "cl-ubun" not found
pod/cl-ubun created
NAME READY STATUS RESTARTS AGE
cl-ubun 0/1 ContainerCreating 0 0s
sv-django 1/1 Running 0 7m35s
sv-https-portal 1/1 Running 0 7m20s
sv-mariadb 1/1 Running 0 18m
root@kubelinux:/microk8s/script# microk8s kubectl get pod ⭐️少し待ったらRunning状態になる
NAME READY STATUS RESTARTS AGE
cl-ubun 1/1 Running 0 22s
sv-django 1/1 Running 0 7m57s
sv-https-portal 1/1 Running 0 7m42s
sv-mariadb 1/1 Running 0 18m
root@kubelinux:/microk8s/script#
フォワーディング#
Podが他のホストから見えるようにする。dashboardはHeadlamp使うように変えた。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
root@kubelinux:/microk8s/script# cat 306_allForwardingStart.sh
## -------------------------------------------------------------------------
## Script Name : 306_allForwardingStart.sh
## Created by : T.Naritomi
## on : 2024.12.24
## Updated by : 2026.08.25
## on :
## Parameters :
## Return Code : 0=Normal End
## Comments :
## -------------------------------------------------------------------------
## ---detail----------------------------------------------------------------
microk8s kubectl port-forward --address 0.0.0.0 ` microk8s kubectl get pod | grep mariadb | awk '{print $1}' ` 13306:3306 &
microk8s kubectl port-forward --address 0.0.0.0 ` microk8s kubectl get pod | grep cl-ubun | awk '{print $1}' ` 33389:3389 &
microk8s kubectl port-forward --address 0.0.0.0 ` microk8s kubectl get pod | grep sv-django | awk '{print $1}' ` 38080:8080 &
microk8s kubectl port-forward --address 0.0.0.0 ` microk8s kubectl get pod | grep sv-https | awk '{print $1}' ` 30443:443 &
microk8s kubectl port-forward -n kube-system service/headlamp 18080:80 --address 0.0.0.0 & ⭐️dashboardやなくHeadlampに変えた
exit $?
root@kubelinux:/microk8s/script# sh ./306_allForwardingStart.sh ⭐️行っけ〜!!
root@kubelinux:/microk8s/script# Forwarding from 0.0.0.0:18080 -> 4466
Forwarding from 0.0.0.0:13306 -> 3306
Forwarding from 0.0.0.0:38080 -> 8080
Forwarding from 0.0.0.0:30443 -> 443
Forwarding from 0.0.0.0:33389 -> 3389
root@kubelinux:/microk8s/script#
kubernetesの状態確認やってみよか。パス通して常用してるonlchkって使う。
dashboardからHeadlampに切り替えたのでトークンがコロコロ変わる。その確認コマンドラインを追記した。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
root@kubelinux:/microk8s/script# cat onlchk
## -------------------------------------------------------------------------
## Script Name : onlchk (for ubuntu24 microk8s)
## Created by : T.Naritomi
## on : 2023.07.27
## Updated by : 2024.11.29
## on :
## Parameters :
## Return Code : 0=Normal End
## Comments : work on x86 in vmware
## -------------------------------------------------------------------------
## ---detail----------------------------------------------------------------
echo '----- cluster status ------'
microk8s status --wait-ready | head -5
echo '------ cluster node ------'
cat /etc/os-release | grep PRETTY_NAME
df -h | grep -v "dev/loop" | grep -v tmpfs | grep -v credentials | grep -v /var/snap/microk8s
echo '----- recent cluster ver -----'
## multipass exec microk8s-vm -- sudo snap info microk8s | grep classic | head -3
## multipass exec microk8s-vm -- sudo snap info microk8s | egrep -v 'installed|beta|edge|candidate' | grep classic | sort -r | head -3
## snap info microk8s | egrep 'stable|installed|stable' | grep classic | grep -v 'tracking' | sort -r | head -4
snap info microk8s | egrep -v 'beta|edge|candidate' | grep classic | sort -r | head -4
echo '------- images in ctr -------'
## multipass exec microk8s-vm -- sudo microk8s.ctr images ls | egrep 'save|maria|https' | awk '{print $1,$4,$5}' | grep -v '@' | sort
microk8s.ctr images ls | grep save | egrep 'save|maria|https' | awk '{print $1,$4,$5}' | grep -v '@' | sort
echo '-------kubectl version -------'
microk8s kubectl version --output= yaml | egrep 'clientVersion|serverVersion|gitVersion'
echo '----kubectl po/svc/configmap status ----'
microk8s kubectl get po,svc,configmap
echo '-------kubectl PV -------'
microk8s kubectl get pv | awk '{ print $1,$2,$3,$5} '
echo '-------kubectl forward -------'
ps -efww | grep kubectl | grep forward | grep -v wrapper | awk '{ print $9,$10,$11,$12,$13 }' | sort
echo '-------kubectl token -------'
microk8s kubectl -n kube-system create token default ⭐️トークン教えてちょ
echo ''
exit $?
root@kubelinux:/microk8s/script# onlchk ⭐️確認してちょ
----- cluster status ------
microk8s is running
high-availability: no
datastore master nodes: 127.0.0.1:19001
datastore standby nodes: none
addons:
------ cluster node ------
PRETTY_NAME= "Ubuntu 26.04 LTS"
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/ubuntu--vg-ubuntu--lv 57G 34G 22G 62% /
/dev/sda2 2.0G 96M 1.7G 6% /boot
//192.168.1.40/kubernetes 932G 417G 515G 45% /microk8s ⭐️windows11のssdドライブをsmbマウントしてるからサイズは無視
----- recent cluster ver -----
latest/stable: v1.36.2 2026-06-24 ( 9044) 181MB classic
installed: v1.36.2 ( 9092) 181MB classic ⭐️時期的にそろそろ1.37になるやろけど今日の最新やな
1.36/stable: v1.36.2 2026-06-30 ( 9092) 181MB classic
1.35/stable: v1.35.6 2026-07-02 ( 9072) 179MB classic
------- images in ctr -------
docker.io/library/save-django:gvis-saved 1.4 GiB
docker.io/library/save-xrdpubu:gvis-saved 7.3 GiB
-------kubectl version -------
clientVersion:
gitVersion: v1.36.2
serverVersion:
gitVersion: v1.36.2
----kubectl po/svc/configmap status ---- ⭐️みなさん元気に動いてくれてまーす
NAME READY STATUS RESTARTS AGE
pod/cl-ubun 1/1 Running 0 8m55s
pod/sv-django 1/1 Running 0 16m
pod/sv-https-portal 1/1 Running 0 16m
pod/sv-mariadb 1/1 Running 0 26m
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT( S) AGE
service/kubernetes ClusterIP 10.152.183.1 <none> 443/TCP 24h
service/sv-django ClusterIP 10.152.183.215 <none> 38080/TCP 24h
service/sv-https-portal ClusterIP 10.152.183.167 <none> 30080/TCP,30443/TCP 24h
service/sv-mariadb ClusterIP 10.152.183.246 <none> 13306/TCP 24h
NAME DATA AGE
configmap/kube-root-ca.crt 1 24h
configmap/sv-mariadb-txt 5 24h
-------kubectl PV -------
NAME CAPACITY ACCESS RECLAIM
gvis-pv-django-sslcerts 1Gi RWO Bound
gvis-pv-django-uwsgi-nginx 1Gi RWO Bound
gvis-pv-mariadb 20Gi RWO Bound
gvis-pv-mariadbconf 5Gi RWO Bound
gvis-pv-ubun 10Gi RWO Bound
pvc-35312942-25d4-4588-a646-b8756aacab52 30Gi RWX Bound
-------kubectl forward -------
port-forward --address 0.0.0.0 cl-ubun 33389:3389
port-forward --address 0.0.0.0 sv-django 38080:8080
port-forward --address 0.0.0.0 sv-https-portal 30443:443
port-forward --address 0.0.0.0 sv-mariadb 13306:3306
port-forward -n kube-system service/headlamp 18080:80
-------kubectl token -------
( 長〜いトークン文字列)
root@kubelinux:/microk8s/script#
ただし、xrdpのPodに最初どうしても接続できんかった。
gemini先生にアドバイスもらって、マニフェストのファイルの記述足した。
cl-ubun-pod.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
apiVersion: v1
kind: Pod
metadata:
name: cl-ubun
labels:
app: cl-ubun
spec:
containers:
- env:
image: save-xrdpubu:gvis-saved
name: cl-ubun
ports:
- containerPort: 3389
resources: {}
volumeMounts: # コンテナ内のどのディレクトリにpersistentVolumeをマウントするか
- name: ubun-persistent-storage1
mountPath: /gvis
securityContext: ⭐️書いとかなrdp接続したときクラッシュする
privileged: true ⭐️書いとかなrdp接続したときクラッシュする
hostAliases:
- ip: "192.168.1.118"
hostnames:
- "nafslinux.intra.gavann-it.com"
- ip: "192.168.1.119"
hostnames:
- "kubelinux.intra.gavann-it.com"
hostname: clubu
restartPolicy: Always
volumes:
- name: ubun-persistent-storage1
persistentVolumeClaim:
claimName: gvis-pv-ubun-claim
# name=gvis-pv-ubun-claimを使って、マウントできるPVを探す
なんで今まで使えてたんやろな。
ここまで来たときのHeadlampの状態。たまに接続切れてまうけど、すぐつながる。
ログ見えたり、Podにログインもできるっぽい。CPUとメモリの利用率はどっかで見えへんのかな。
複雑な構成やったらマップってのがあったほうが全体を俯瞰できてええんやろけど、あんまり使わんな。
mariadbのパラメータ渡ってきて業務データも入ったやん。
djangoアプリのバージョンが6.1.0で動いとる。
matplotlibのグラフ表示もOK。
データベースもgoogle cloudから持ってきた今月のデータ読めとる。
cpuの利用率やメモリ利用率と通信速度は平常どおりでvscodeでgitgraphも見えとった。docker環境で設定したGUI設定ちゃんと入っとる。
今回はkubernetes側の設定で手間取ったな。
次また2年後もがんばらなアカンけど、macの中のarm64-ubuntuがまだ24やったな。
来週がんばるか。