Senin, 04 November 2024

VIRCTL-remote kubernetes

 

Using virtctl to access virtual machine in Kubernetes

Install the virtctl client tool

Basic VirtualMachineInstance operations can be performed with the stock kubectl utility. However, the virtctl binary utility is required to use advanced features such as:

  • Serial and graphical console access

It also provides convenience commands for:

  • Starting and stopping VirtualMachineInstances
  • Live migrating VirtualMachineInstances
  • Uploading virtual machine disk images

There are two ways to get it:

  • the most recent version of the tool can be retrieved from the official release page
  • it can be installed as a kubectl plugin using krew

Example:

$ export VERSION=v0.48.1
$ wget https://github.com/kubevirt/kubevirt/releases/download/${VERSION}/virtctl-${VERSION}-linux-amd64
$ ln -s virtctl-v0.48.1-linux-amd64 virtctl
$ chmod +x virtctl-v0.48.1-linux-amd64
$ ./virtctl version
Client Version: version.Info{GitVersion:"v0.48.1", ...}

Access the virtual machine console

$ ./virtctl -h
virtctl controls virtual machine related operations on your kubernetes cluster.

Available Commands:
  addvolume         add a volume to a running VM
  console           Connect to a console of a virtual machine instance.
  expose            Expose a virtual machine instance, virtual machine, or virtual machine instance replica set as a new service.
  fslist            Return full list of filesystems available on the guest machine.
  guestfs           Start a shell into the libguestfs pod
  guestosinfo       Return guest agent info about operating system.
  help              Help about any command
  image-upload      Upload a VM image to a DataVolume/PersistentVolumeClaim.
  migrate           Migrate a virtual machine.
  pause             Pause a virtual machine
  permitted-devices List the permitted devices for vmis.
  port-forward      Forward local ports to a virtualmachine or virtualmachineinstance.
  removevolume      remove a volume from a running VM
  restart           Restart a virtual machine.
  soft-reboot       Soft reboot a virtual machine instance
  ssh               Open a SSH connection to a virtual machine instance.
  start             Start a virtual machine.
  stop              Stop a virtual machine.
  unpause           Unpause a virtual machine
  usbredir          Redirect a usb device to a virtual machine instance.
  userlist          Return full list of logged in users on the guest machine.
  version           Print the client and server version information.
  vnc               Open a vnc connection to a virtual machine instance.

Use "virtctl <command> --help" for more information about a given command.
Use "virtctl options" for a list of global command-line options (applies to all commands).

$ ./virtctl console vm1
[root@vm1 output]# hostname
vm1

Reference

COZYSTACK-install OK

https://cozystack.io/docs/get-started/
https://blog.aenix.io/installing-a-kubernetes-cluster-managed-by-cozystack-a-detailed-guide-by-gohost-and-%C3%A6nix-2b2d2e0ddbdb

dbsa@dbsa-X406UA
:~$ ssh root@172.16.79.5
Welcome to Ubuntu 22.04 LTS (GNU/Linux 4.15.0-213-generic x86_64)

* Documentation:  https://help.ubuntu.com
* Management:     https://landscape.canonical.com
* Support:        https://ubuntu.com/advantage

 

Setting up nmap (7.91+dfsg1+really7.80+dfsg1-2ubuntu0.1) ...

Processing triggers for man-db (2.10.2-1) ...
Processing triggers for libc-bin (2.35-0ubuntu3.8) ...
Выберите версию talos клиента для скачивания:
1) v1.8.2
2) v1.9.0-alpha.0
3) v1.8.1
4) v1.7.7
5) v1.8.0
6) v1.8.0-beta.1
7) v1.8.0-beta.0
8) v1.8.0-alpha.2
9) v1.7.6
10) v1.6.8
#? 9
Вы выбрали версию v1.7.6
--2024-11-04 15:40:06--  https://github.com/siderolabs/talos/releases/download/v1.7.6/talosctl-linux-amd64
Resolving github.com (github.com)... 20.205.243.166
Connecting to github.com (github.com)|20.205.243.166|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://objects.githubusercontent.com/github-production-release-asset-2e65be/109451092/9cda616a-dab1-41cd-846e-e540a97e3d44?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=releaseassetproduct
ion%2F20241104%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20241104T084007Z&X-Amz-Expires=300&X-Amz-Signature=1d01f0e214c786a15e233aa05911e2b19368add5177de294f0dd86036e74dba7&X-Amz-SignedHeaders=host&resp
onse-content-disposition=attachment%3B%20filename%3Dtalosctl-linux-amd64&response-content-type=application%2Foctet-stream [following]
--2024-11-04 15:40:07--  https://objects.githubusercontent.com/github-production-release-asset-2e65be/109451092/9cda616a-dab1-41cd-846e-e540a97e3d44?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=rele
aseassetproduction%2F20241104%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20241104T084007Z&X-Amz-Expires=300&X-Amz-Signature=1d01f0e214c786a15e233aa05911e2b19368add5177de294f0dd86036e74dba7&X-Amz-SignedHe
aders=host&response-content-disposition=attachment%3B%20filename%3Dtalosctl-linux-amd64&response-content-type=application%2Foctet-stream
Resolving objects.githubusercontent.com (objects.githubusercontent.com)... 185.199.111.133, 185.199.109.133, 185.199.108.133, ...
Connecting to objects.githubusercontent.com (objects.githubusercontent.com)|185.199.111.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 79237272 (76M) [application/octet-stream]
Saving to: ‘talosctl’

talosctl                                           100%[===============================================================================================================>]  75,57M  13,7MB/s    in 6,0s     

2024-11-04 15:40:14 (12,6 MB/s) - ‘talosctl’ saved [79237272/79237272]

Получаем список доступных версий kubectl...
Выберите версию kubectl для скачивания:
1) v1.30.4
2) v1.29.8
#? 1
Вы выбрали версию v1.30.4
Загружается kubectl версия v1.30.4 ...
 % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                Dload  Upload   Total   Spent    Left  Speed
100 49.0M  100 49.0M    0     0  10.0M      0  0:00:04  0:00:04 --:--:-- 11.7M
kubectl версия v1.30.4 успешно установлена!
Получаем список доступных версий Helm...
Доступные версии Helm:
1) v3.16.2
2) v3.16.1
3) v3.16.0
4) v3.16.0
5) v3.15.4
6) v3.15.3
7) v3.15.2
8) v3.15.1
9) v3.15.0
10) v3.15.0
#? 1
Скачиваем и устанавливаем Helm версии v3.16.2...
Downloading https://get.helm.sh/helm-v3.16.2-linux-amd64.tar.gz
Verifying checksum... Done.
Preparing to install helm into /usr/local/bin
helm installed into /usr/local/bin/helm
Helm версии v3.16.2 успешно установлен!
version.BuildInfo{Version:"v3.16.2", GitCommit:"13654a52f7c70a143b1dd51416d633e1071faffb", GitTreeState:"clean", GoVersion:"go1.22.7"}
 % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                Dload  Upload   Total   Spent    Left  Speed
 0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100  4912  100  4912    0     0   5225      0 --:--:-- --:--:-- --:--:--  768k
Получаем список доступных версий talm
Доступные версии:
1) v0.6.4     3) v0.6.2    5) v0.6.0    7) v0.5.11   9) v0.5.8   11) v0.5.6   13) v0.5.4   15) v0.5.2   17) v0.5.0   19) v0.3.1   21) v0.2.2   23) v0.2.0   25) v0.1.0
2) v0.6.3     4) v0.6.1    6) v0.5.12   8) v0.5.10  10) v0.5.7   12) v0.5.5   14) v0.5.3   16) v0.5.1   18) v0.4.0   20) v0.3.0   22) v0.2.1   24) v0.1.1
#? 1
Скачиваем talm версии v0.6.4...
 % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                Dload  Upload   Total   Spent    Left  Speed
 0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100 97.9M  100 97.9M    0     0  10.3M      0  0:00:09  0:00:09 --:--:-- 13.3M
Проверка установки...
talm version 0.6.4
talm успешно установлен!
Укажите название директории для конфигурационных файлов,
директория будет располагаться в каталоге /opt/. По умолчанию: /opt/cozystack

Введите название директории:                                                                                                                                                                                
                                                                                                                                                                                                           
 % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                Dload  Upload   Total   Spent    Left  Speed
 0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100 21727  100 21727    0     0  23555      0 --:--:-- --:--:-- --:--:-- 23555
yq v4.44.2 from Mike Farah (mikefarah) installed
Укажите IP-сеть для  etcd и kubelet
По умолчанию:  192.168.100.0/24  
IP-сеть (network/mask): 172.16.79.0/24
grep: : No such file or directory
net.ipv4.ip_forward = 1
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
 libwpe-1.0-1 libwpebackend-fdo-1.0-1
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
 netfilter-persistent
The following NEW packages will be installed:
 iptables-persistent netfilter-persistent
0 upgraded, 2 newly installed, 0 to remove and 3 not upgraded.
Need to get 13,9 kB of archives.
After this operation, 93,2 kB of additional disk space will be used.
Get:1 http://id.archive.ubuntu.com/ubuntu jammy/universe amd64 netfilter-persistent all 1.0.16 [7.440 B]
Get:2 http://id.archive.ubuntu.com/ubuntu jammy/universe amd64 iptables-persistent all 1.0.16 [6.488 B]
Fetched 13,9 kB in 1s (21,9 kB/s)          
Preconfiguring packages ...
Selecting previously unselected package netfilter-persistent.
(Reading database ... 167872 files and directories currently installed.)
Preparing to unpack .../netfilter-persistent_1.0.16_all.deb ...
Unpacking netfilter-persistent (1.0.16) ...
Selecting previously unselected package iptables-persistent.
Preparing to unpack .../iptables-persistent_1.0.16_all.deb ...
Unpacking iptables-persistent (1.0.16) ...
Setting up netfilter-persistent (1.0.16) ...
Created symlink /etc/systemd/system/multi-user.target.wants/netfilter-persistent.service → /lib/systemd/system/netfilter-persistent.service.
Setting up iptables-persistent (1.0.16) ...
update-alternatives: using /lib/systemd/system/netfilter-persistent.service to provide /lib/systemd/system/iptables.service (iptables.service) in auto mode
Processing triggers for man-db (2.10.2-1) ...


>>> Welcome to Webi! - modern tools, instant installs.  <<<
   We expect your experience to be absolutely perfect!

   Success? Star it!   https://github.com/webinstall/webi-installers
   Problem? Report it: https://github.com/webinstall/webi-installers/issues
                       (your system is GNU/Linux/x86_64 with libc & curl+wget)

Bootstrapping Webi
   Downloading https://webinstall.dev/packages/webi/webi.sh
       to ~/.local/bin/webi
   Running ~/.local/bin/webi k9s@stable

Installing k9s ...
   Found  ~/.local/bin
   Initializing ~/.config/envman/
   Edit ~/.profile to source ~/.config/envman/load.sh
   Edit ~/.bashrc to source ~/.config/envman/load.sh
   Downloading k9s from
     https://github.com/derailed/k9s/releases/download/v0.32.5/k9s_Linux_amd64.tar.gz
   Saved as ~/Downloads/webi/k9s/0.32.5/k9s_Linux_amd64.tar.gz
   Extracting ~/Downloads/webi/k9s/0.32.5/k9s_Linux_amd64.tar.gz
   Installing to ~/.local/opt/k9s-v0.32.5/bin/k9s

   Installed 'k9s v0.32.5' as ~/.local/bin/k9s

   Edit ~/.config/envman/PATH.env to add:
       ~/.local/bin

>>> ACTION REQUIRED <<<
       Copy, paste & run the following command:
       source ~/.config/envman/PATH.env
       (newly opened terminal windows will update automatically)

talm       in folder /usr/local/bin/talm
cp: cannot stat 'kubeconfig': No such file or directory
cp: cannot stat 'talosconfig': No such file or directory
========== Installed binary ===========
helm       in folder /usr/local/bin/helm
yq         in folder /snap/bin/yq
kubectl    in folder /usr/local/bin/kubectl
docker     in folder /usr/bin/docker
talosctl   in folder /usr/local/bin/talosctl
dialog     in folder /usr/bin/dialog
nmap       in folder /usr/bin/nmap
talm       in folder /usr/local/bin/talm
k9s       in folder /root/.local/bin/k9s
node_shell       in folder /usr/local/bin/kubectl-node_shell
========== services runing ===========
DNS Bind9       active
NTP             active                                                                                                                                                                                      
========== ADD Iptables Rule ===========                                                                                                                                                                    
-A FORWARD -s 172.16.79.0/24 -m comment --comment cozystack -j ACCEPT
-A FORWARD -d 172.16.79.0/24 -m state --state RELATED,ESTABLISHED -m comment --comment cozystack -j ACCEPT
-A POSTROUTING -s 172.16.79.0/24 -m comment --comment cozystack -j MASQUERADE
!!!  Please change the catalog to work with talos-bootstrap !!!
cd  /opt/cozystack  
root@ubuntu-virtual-machine:~/cozystack# cd /opt/cozystack/
root@ubuntu-virtual-machine:/opt/cozystack# ls
patch-controlplane.yaml  patch.yaml  talos-bootstrap
root@ubuntu-virtual-machine:/opt/cozystack# . talos-bootstrap install
awk: line 1: regular expression compile failed (missing operand)
*"$
generating PKI and tokens
Created /opt/cozystack/controlplane.yaml
Created /opt/cozystack/worker.yaml
Created /opt/cozystack/talosconfig
Dry run summary:
Node is running in maintenance mode and does not have a config yet.
root@ubuntu-virtual-machine:/opt/cozystack# . talos-bootstrap install
awk: line 1: regular expression compile failed (missing operand)
*"$
generating PKI and tokens
Created /opt/cozystack/controlplane.yaml
Created /opt/cozystack/worker.yaml
Created /opt/cozystack/talosconfig
Dry run summary:
Node is running in maintenance mode and does not have a config yet.
root@ubuntu-virtual-machine:/opt/cozystack# . talos-bootstrap install
awk: line 1: regular expression compile failed (missing operand)
*"$
generating PKI and tokens
Created /opt/cozystack/controlplane.yaml
Created /opt/cozystack/worker.yaml
Created /opt/cozystack/talosconfig
Dry run summary:
Node is running in maintenance mode and does not have a config yet.
root@ubuntu-virtual-machine:/opt/cozystack#