進化を続けるクラウドネイティブコンピューティングにおいて、Kubernetesほど大きな影響力を持つ技術はほとんどない。
10周年を迎えるKubernetesは、オープンソースが持つ協力と革新の力を証明する存在になっている。Googleでつつましく始まったKubernetesは、アプリケーションのデプロイ、管理、スケーリングのあり方を変え、コンテナーオーケストレーションのデファクトスタンダードになった。
⇧ 構築や保守・運用の負担についても改善を進めて欲しいんだが...
「Kubernetes職人」に依存せざるを得ないような流れは止めて欲しいところですな...
何というか「属人化」に蝕まれていく気はしますな...
VirtualBoxのNetworking Modesとネットワークの関係を整理してみる
後述する「Vagrantfile」の設定で泥沼にハマったので、「VirtualBox」の「Networking Modes」なるものと「ネットワーク」の関係を調べてみたので備忘録として。
「VirtualBox」の公式のドキュメントによりますと、
⇧ 上記が通信のパターンの全量ってことで良いのか分からないのだが、
No | VirtualBox | |||||
---|---|---|---|---|---|---|
Networking Modes | 通信範囲 | |||||
自分のPCのみの話 | 自分のPCと外部のPCの話 | |||||
VM→HOST | VM←HOST | VM1↔VM2 | VM→Net/LAN | VM←Net/LAN | ||
1 | Host-only | ✅ | ✅ | ✅ | ✖ | ✖ |
2 | Internal | ✖ | ✖ | ✅ | ✖ | ✖ |
3 | Bridged | ✅ | ✅ | ✅ | ✅ | ✅ |
4 | NAT | ✅ | ※1 | ✖ | ✅ | ※1 |
5 | NATservice | ✅ | ※1 | ✅ | ✅ | ※1 |
※1 Port Forward
⇧ ということになるんだと思われる。
ザックリと、
に話が分かれますと。
例えば、「会社」に配置されているPCに「VirtualBox」で「仮想マシン(VM: Virtual Machine)」を構築・起動させておいて、「自宅」などで別のPCから接続しに行くような話は『2. 自分のPCと外部のPCの話』になるわけだ。
「VM←Net/LAN」のパターンになると、
など、環境を用意するのが結構面倒ではある。
「VirtualBox」などの「仮想マシン(VM: Virtual Machine)」で稼働している「アプリケーション」が「クラウド」のサービスを利用するような場合は、「クラウド」側で通信の許可の制限とかされてることもあり「クラウド」側での対応が必要にはなりますと。
各「Networking Modes」が、どういう通信の構成になっているのかについては、
⇧ 上記サイト様が詳しいので引用させていただく。
■【Networking Modes】Host-only
■【Networking Modes】Internal
■【Networking Modes】Bridged
■【Networking Modes】NAT
■【Networking Modes】NATservice
とりあえず、「VirtualBox」の公式のドキュメントの「Networking Modes」のマトリックス表が正しいと仮定して話を進めることにしますが、「【Networking Modes】Internal」の場合は、「ホスト側」から「ゲスト側」に接続できない、つまり「VirtualBox」の構築している「仮想マシン(VM: Virtual Machine)」に接続できませんと。
Vagrantfileのネットワークの設定で泥沼にハマる
で、
- 「VirtualBox」の「Networking Modes」
- 「Vagrantfile」の「ネットワーク設定」
の関係がよく分かって無かったので、ネットの情報に躍らされてしまい、不毛な時間を費やすことになってしまいましたと...
例のごとく、「ChatGPT」先生も「幻覚(ハルシネーション)」が絶好調で解決策を提示してくれなかったので、結局、自力で解決することになりました...
■Vagrantfile
# 仮想マシンの台数 hosts = { "host1" => "192.168.56.11", "host2" => "192.168.56.12" } Vagrant.configure("2") do |config| config.vm.boot_timeout = 600 ### OS(Operation System) # Linuxディストリビューション config.vm.box = "rockylinux/9" # config.vm.box_version = "4.0.0" # 公式のリポジトリ config.vm.box_url = "https://dl.rockylinux.org/pub/rocky/9.5/images/x86_64/Rocky-9-Vagrant-Vbox-9.5-20241118.0.x86_64.box" config.vm.box_download_checksum = "5323e2b3007975c60c9a6bab27548e567ec3df41a7cde7ce2bfd7acf15f3b067" config.vm.box_download_checksum_type = "sha256" # 仮想マシンを構築する hosts.each_with_index do |(hostname, ipv4), index| config.vm.define "vm-sandbox-0#{index + 1}" do |machine| ### プロバイダー(仮想ソフトウェア)毎の設定 machine.vm.provider "virtualbox" do |vb| # 仮想マシン名 vb.name = "vm-sandbox-rocky-0#{index + 1}" vb.memory = "1024" vb.cpus = 2 # vb.customize ["modifyvm", :id, "--cableconnected1", "on"] end # ディスクサイズ # ※ Vagrant 2.4.0以降、且つ、プロバイダー(仮想ソフトウェア)がVirtualBoxの場合だけ有効 machine.vm.disk :disk, primary: true, size: "50GB" # ネットワーク設定 (プライベートネットワーク) # machine.vm.network "private_network", ip: ipv4, virtualbox__intnet: true machine.vm.network "private_network", ip: ipv4 # ポートフォワーディング設定 machine.vm.network :forwarded_port, id: "ssh", guest: 22, host: "220#{index + 1}", auto_correct: true, :netmask => "255.255.0.0" # SSH設定(必要に応じて追加) # machine.ssh.extra_args = ["-o", "PubkeyAcceptedKeyTypes=+ssh-rsa", "-o", "HostKeyAlgorithms=+ssh-rsa"] # machine.ssh.host = ipv4 end end end
⇧ポイントは、「ネットワーク」の設定で「virtualbox__intnet: true」を追加してしまうと(コメントアウトして無効にしているが、灰色の行)、「【Networking Modes】Internal」の扱いになるらしく、「ホスト側」から「ゲスト側」へ通常のSSH接続ができませんと。
「virtualbox__intnet: true」を追加しない場合は、「【Networking Modes】Host-only」の扱いになるらしいので通常のSSH接続が可能になりますと。
ちなみに、
⇧ 上記の情報に完全に騙されましたわ...
「vagrant ssh」ができるようになるのであって、「ssh」ができるわけではなかったということかね...
と言うか、質問が『「vagrant ssh」を使わずに「ssh」で接続する方法を知りたい』ってことだと思うのに、「vagrant ssh」する方法を回答してくるのは、紛らわしいので止めて欲しいのよね...
せめて、『質問に対する回答にはならないが、別解として~』みたいな前置きを入れて欲しい気はする...
まぁ、「Vagrant」内部の処理がブラックボックス過ぎてよく分からんのだが、「Vagrant」内部のデフォルトの処理によるのか「127.0.0.1」に対してSSH接続の設定が為される模様。
「vagrant ssh」が機能するは、このあたりの「Vagrant」内部の処理によるのだと思われますと。
vagrant ssh <仮想マシン名>
⇧ は普通に機能するので「Vagrant」のよく分からない仕組みで「SSH」接続自体は可能ですと。
以下、「vagrant up」の実行結果など。
D:\work-soft\vagrant\distro\rockylinux\9>vagrant up Bringing machine 'vm-sandbox-01' up with 'virtualbox' provider... Bringing machine 'vm-sandbox-02' up with 'virtualbox' provider... ==> vm-sandbox-01: Importing base box 'rockylinux/9'... ==> vm-sandbox-01: Matching MAC address for NAT networking... ==> vm-sandbox-01: Setting the name of the VM: vm-sandbox-rocky-01 ==> vm-sandbox-01: Clearing any previously set network interfaces... ==> vm-sandbox-01: Preparing network interfaces based on configuration... vm-sandbox-01: Adapter 1: nat vm-sandbox-01: Adapter 2: hostonly ==> vm-sandbox-01: Forwarding ports... vm-sandbox-01: 22 (guest) => 2201 (host) (adapter 1) ==> vm-sandbox-01: Configuring storage mediums... vm-sandbox-01: Disk 'vagrant_primary' needs to be resized. Resizing disk... ==> vm-sandbox-01: Running 'pre-boot' VM customizations... ==> vm-sandbox-01: Booting VM... ==> vm-sandbox-01: Waiting for machine to boot. This may take a few minutes... vm-sandbox-01: SSH address: 127.0.0.1:2201 vm-sandbox-01: SSH username: vagrant vm-sandbox-01: SSH auth method: private key vm-sandbox-01: vm-sandbox-01: Vagrant insecure key detected. Vagrant will automatically replace vm-sandbox-01: this with a newly generated keypair for better security. vm-sandbox-01: vm-sandbox-01: Inserting generated public key within guest... vm-sandbox-01: Removing insecure key from the guest if it's present... vm-sandbox-01: Key inserted! Disconnecting and reconnecting using new SSH key... ==> vm-sandbox-01: Machine booted and ready! ==> vm-sandbox-01: Checking for guest additions in VM... vm-sandbox-01: No guest additions were detected on the base box for this VM! Guest vm-sandbox-01: additions are required for forwarded ports, shared folders, host only vm-sandbox-01: networking, and more. If SSH fails on this machine, please install vm-sandbox-01: the guest additions and repackage the box to continue. vm-sandbox-01: vm-sandbox-01: This is not an error message; everything may continue to work properly, vm-sandbox-01: in which case you may ignore this message. ==> vm-sandbox-01: Configuring and enabling network interfaces... ==> vm-sandbox-01: Rsyncing folder: /cygdrive/d/work-soft/vagrant/distro/rockylinux/9/ => /vagrant ==> vm-sandbox-02: Importing base box 'rockylinux/9'... ==> vm-sandbox-02: Matching MAC address for NAT networking... ==> vm-sandbox-02: Setting the name of the VM: vm-sandbox-rocky-02 ==> vm-sandbox-02: Clearing any previously set network interfaces... ==> vm-sandbox-02: Preparing network interfaces based on configuration... vm-sandbox-02: Adapter 1: nat vm-sandbox-02: Adapter 2: hostonly ==> vm-sandbox-02: Forwarding ports... vm-sandbox-02: 22 (guest) => 2202 (host) (adapter 1) ==> vm-sandbox-02: Configuring storage mediums... vm-sandbox-02: Disk 'vagrant_primary' needs to be resized. Resizing disk... ==> vm-sandbox-02: Running 'pre-boot' VM customizations... ==> vm-sandbox-02: Booting VM... ==> vm-sandbox-02: Waiting for machine to boot. This may take a few minutes... vm-sandbox-02: SSH address: 127.0.0.1:2202 vm-sandbox-02: SSH username: vagrant vm-sandbox-02: SSH auth method: private key vm-sandbox-02: vm-sandbox-02: Vagrant insecure key detected. Vagrant will automatically replace vm-sandbox-02: this with a newly generated keypair for better security. vm-sandbox-02: vm-sandbox-02: Inserting generated public key within guest... vm-sandbox-02: Removing insecure key from the guest if it's present... vm-sandbox-02: Key inserted! Disconnecting and reconnecting using new SSH key... ==> vm-sandbox-02: Machine booted and ready! ==> vm-sandbox-02: Checking for guest additions in VM... vm-sandbox-02: No guest additions were detected on the base box for this VM! Guest vm-sandbox-02: additions are required for forwarded ports, shared folders, host only vm-sandbox-02: networking, and more. If SSH fails on this machine, please install vm-sandbox-02: the guest additions and repackage the box to continue. vm-sandbox-02: vm-sandbox-02: This is not an error message; everything may continue to work properly, vm-sandbox-02: in which case you may ignore this message. ==> vm-sandbox-02: Configuring and enabling network interfaces... ==> vm-sandbox-02: Rsyncing folder: /cygdrive/d/work-soft/vagrant/distro/rockylinux/9/ => /vagrant D:\work-soft\vagrant\distro\rockylinux\9>vagrant ssh-config Host vm-sandbox-01 HostName 127.0.0.1 User vagrant Port 2201 UserKnownHostsFile /dev/null StrictHostKeyChecking no PasswordAuthentication no IdentityFile D:/work-soft/vagrant/distro/rockylinux/9/.vagrant/machines/vm-sandbox-01/virtualbox/private_key IdentitiesOnly yes LogLevel FATAL PubkeyAcceptedKeyTypes +ssh-rsa HostKeyAlgorithms +ssh-rsa Host vm-sandbox-02 HostName 127.0.0.1 User vagrant Port 2202 UserKnownHostsFile /dev/null StrictHostKeyChecking no PasswordAuthentication no IdentityFile D:/work-soft/vagrant/distro/rockylinux/9/.vagrant/machines/vm-sandbox-02/virtualbox/private_key IdentitiesOnly yes LogLevel FATAL PubkeyAcceptedKeyTypes +ssh-rsa HostKeyAlgorithms +ssh-rsa D:\work-soft\vagrant\distro\rockylinux\9>ssh vagrant@192.168.56.11 -i D:/work-soft/vagrant/distro/rockylinux/9/.vagrant/machines/vm-sandbox-01/virtualbox/private_key The authenticity of host '192.168.56.11 (192.168.56.11)' can't be established. ED25519 key fingerprint is SHA256:x6XwB84u8+udGjYjrZUTLvDBgDEm4aFl4g7Ac/oEqMg. This key is not known by any other names. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added '192.168.56.11' (ED25519) to the list of known hosts. [vagrant@vbox ~]$ ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 00:16:3e:0e:40:a1 brd ff:ff:ff:ff:ff:ff altname enp0s3 inet 10.0.2.15/24 brd 10.0.2.255 scope global dynamic noprefixroute eth0 valid_lft 86222sec preferred_lft 86222sec inet6 fd00::216:3eff:fe0e:40a1/64 scope global dynamic mngtmpaddr valid_lft 86224sec preferred_lft 14224sec inet6 fe80::216:3eff:fe0e:40a1/64 scope link valid_lft forever preferred_lft forever 3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 08:00:27:0f:74:3b brd ff:ff:ff:ff:ff:ff altname enp0s8 inet 192.168.56.11/24 brd 192.168.56.255 scope global noprefixroute eth1 valid_lft forever preferred_lft forever inet6 fe80::a00:27ff:fe0f:743b/64 scope link valid_lft forever preferred_lft forever [vagrant@vbox ~]$ pwd /home/vagrant [vagrant@vbox ~]$ cat /etc/os-release NAME="Rocky Linux" VERSION="9.5 (Blue Onyx)" ID="rocky" ID_LIKE="rhel centos fedora" VERSION_ID="9.5" PLATFORM_ID="platform:el9" PRETTY_NAME="Rocky Linux 9.5 (Blue Onyx)" ANSI_COLOR="0;32" LOGO="fedora-logo-icon" CPE_NAME="cpe:/o:rocky:rocky:9::baseos" HOME_URL="https://rockylinux.org/" VENDOR_NAME="RESF" VENDOR_URL="https://resf.org/" BUG_REPORT_URL="https://bugs.rockylinux.org/" SUPPORT_END="2032-05-31" ROCKY_SUPPORT_PRODUCT="Rocky-Linux-9" ROCKY_SUPPORT_PRODUCT_VERSION="9.5" REDHAT_SUPPORT_PRODUCT="Rocky Linux" REDHAT_SUPPORT_PRODUCT_VERSION="9.5" [vagrant@vbox ~]$
とりあえず、「Vagrantfile」のドキュメントを確認したけども、
⇧「virtualbox__intnet」についての説明が無いのよね...
「ファインダビリティ(Findability)」の問題なのか、公式のドキュメントでは言及されていないのか、ハッキリしないのだが、必要な情報に辿り着けないドキュメントになっているのはなかなかに辛い...
一次情報が頼りにならないのは厳しいのよね...
プロジェクトに1人は、「Vagrant」に精通している「Vagrant職人」を抱えるしかない感じなのかね?
毎度モヤモヤ感が半端ない…
今回はこのへんで。