If you are trying to restore a boot using Windows 10/11 installed on GPT partition from the command line (bootrec /fixboot) in recovery mode of the installation media and getting the error “Access denied”, do the following:

  1. Run the commands
    diskpart
    list volume

    looking for the number of FAT32 partition with the EFI bootloader, and also current letter of our system’s drive C (might be another or also can be not assigned)

  2. Choosing partition with the bootloader an assigning the letter:
    select volume N
    assign letter=L

    Instead of N needs to use the number of the partition and instead of L any currently not used drive letter.

  3. If the system drive (C) is also without letter, assigning the letter same way
  4. Enter exit to close DISKPART.
  5. Executing the follwong command (use your drive letters instead, C in this example is where the system stored, L – assigned by us letter of the EFI partition)
    bcdboot C:\windows /s L: /f UEFI

If you have a VPS or a Dedicated Server with /64 IPv6 subnet and want to use it on your device at home to make it accessible from the internet directly, you can make a tunnel through the Yggdrasil network.

Yggdrasil network is already end to end encrypted, so we can use vxlan over it for this purpose.

On the server with IPv6 subnet we have to install bridge-utils and configure bridge to our external interface:
apt install bridge-utils
brctl addbr br0
brctl addif br0 eth0

then we need to add a vxlan to the server and connect it to the bridge also:
ip link add vxlan0 type vxlan id 42 local $YGGDRASIL_SERVER_IP remote $YGGDRASIL_HOME_IP dstport 4789

where $YGGDRASIL_SERVER_IP and $YGGDRASIL_HOME_IP – your server’s IP in the Yggdrasil network, and home device’s IP in the Yggdrasil network accordingly.

Making the interfaces up:
ip link set up br0
ip link set up vxlan0

Now we are going to the home device:
ip link add vxlan0 type vxlan id 42 local $YGGDRASIL_HOME_IP remote $YGGDRASIL_SERVER_IP dstport 4789
ip link set up vxlan0
ip a a $your_real_ip_from_the_servers_subnet/64 dev vxlan0
route -6 add default gw $your_servers_ipv6_gateway

Thats it.

How to install and configura Yggdrasil network read on the developer’s website. Maybe I’ll write an article later.

I used Ubuntu 20.04 on all the servers. This manual is also suitable for baremetal setup.
In this manual we will use 7 VMs in the same 10.0.0.0/24 network:

  • Kubeapi Load Balancer with HAProxy (10.0.0.90)
  • 3x master nodes (10.0.0.71-10.0.0.73)
  • 3x worker nodes (10.0.0.81-83)

The best way to create 7x VM quickly is to prepare one and clone it (or it’s disk image) before the cluster setup. Once the OS (Ubuntu/Debian) installed, perform the package update and upgrade:

sudo apt update && sudo apt upgrade

If you setting up a VM and clonning it, it needs to change the machine ID and host SSH keys:

rm -f /etc/machine-id
dbus-uuidgen --ensure=/etc/machine-id
rm /var/lib/dbus/machine-id
dbus-uuidgen --ensure
/bin/rm -v /etc/ssh/ssh_host_*
dpkg-reconfigure openssh-server
systemctl restart ssh
reboot

Installing CA and creating certificates

We will use CFSSL tool from Cloudflare
wget https://pkg.cfssl.org/R1.2/cfssl_linux-amd64
wget https://pkg.cfssl.org/R1.2/cfssljson_linux-amd64
chmod +x cfssl*
sudo mv cfssl_linux-amd64 /usr/local/bin/cfssl
sudo mv cfssljson_linux-amd64 /usr/local/bin/cfssljson

Check:
cfssl version

Installing HAProxy as kubeapi load balancer

On the kubeapi load balancer node (10.0.0.90) performing:
sudo apt install haproxy
then the configuration needs to be changed, editing /etc/haproxy/haproxy.cfg:

global
log /dev/log local0
log /dev/log local1 notice
chroot /var/lib/haproxy
stats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listeners
stats timeout 30s
user haproxy
group haproxy
daemon

# Default SSL material locations
ca-base /etc/ssl/certs
crt-base /etc/ssl/private

# See: https://ssl-config.mozilla.org/#server=haproxy&server-version=2.0.3&config=intermediate
ssl-default-bind-ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384
ssl-default-bind-ciphersuites TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256
ssl-default-bind-options ssl-min-ver TLSv1.2 no-tls-tickets

defaults
log global
mode http
option httplog
option dontlognull
timeout connect 5000
timeout client 50000
timeout server 50000
errorfile 400 /etc/haproxy/errors/400.http
errorfile 403 /etc/haproxy/errors/403.http
errorfile 408 /etc/haproxy/errors/408.http
errorfile 500 /etc/haproxy/errors/500.http
errorfile 502 /etc/haproxy/errors/502.http
errorfile 503 /etc/haproxy/errors/503.http
errorfile 504 /etc/haproxy/errors/504.http

# PART BEFORE IS NOT CHANGED, ONLY THE FOLLOWING ADDED:

frontend kubernetes
bind 10.0.0.90:6443
option tcplog
mode tcp
default_backend kubernetes-master-nodes

backend kubernetes-master-nodes
mode tcp
balance roundrobin
option tcp-check
server master01 10.0.0.71:6443 check fall 3 rise 2
server master02 10.0.0.72:6443 check fall 3 rise 2
server master03 10.0.0.73:6443 check fall 3 rise 2

applying configuration:

sudo systemctl restart haproxy

Creating a CA and generating the certificates

Create a file for the certification authority configuration ca-config.json with the following content:

{
"signing": {
"default": {
"expiry": "8760h"
},
"profiles": {
"kubernetes": {
"usages": ["signing", "key encipherment", "server auth", "client auth"],
"expiry": "8760h"
}
}
}
}

Create the certificate authority signing request file ca-csr.json with the following content:

{
"CN": "Kubernetes",
"key": {
"algo": "rsa",
"size": 2048
},
"names": [
{
"C": "IN",
"L": "Ukraine",
"O": "Organization",
"OU": "CA",
"ST": "State"
}
]
}

Generate the certificate authority certificate and private key:
cfssl gencert -initca ca-csr.json | cfssljson -bare ca
Check if the files appeared in the current directory.

Generate the certificate for the Etcd cluster, make the certificate signing request configuration file kubernetes-csr.json with the following content:

{
"CN": "Kubernetes",
"key": {
"algo": "rsa",
"size": 2048
},
"names": [
{
"C": "IN",
"L": "Ukraine",
"O": "Organization",
"OU": "CA",
"ST": "State"
}
]
}

and generate the certificate and private key, to the -hostname add you IPs of HAProxy kubeapi load balancer and master nodes:

cfssl gencert \
-ca=ca.pem \
-ca-key=ca-key.pem \
-config=ca-config.json \
-hostname=10.0.0.90,10.0.0.71,10.0.0.72,10.0.0.73,127.0.0.1,kubernetes.default \
-profile=kubernetes kubernetes-csr.json | \
cfssljson -bare kubernetes

Check if the files appeared.

Copy certificates ca.pem, kubernetes.pem and kubernetes-key.pem to each node, for example to the /home/user directory.

Preparing master nodes and setting up required packages

On all the master nodes:

sudo apt-get remove docker docker-engine docker.io containerd runc

sudo apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"sudo apt-get remove docker docker-engine docker.io containerd runc

sudo apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"

sudo apt-get install -y docker-ce docker-ce-cli containerd.io

sudo usermod -aG docker ubuntu

curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -

sudo mkdir -p /etc/apt/keyrings/
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.29/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.29/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list

sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl

swapoff -a

and remove swap from /etc/fstab.

Setting up the Etcd high available cluster

On the master nodes:

sudo mkdir /etc/etcd /var/lib/etcd
sudo mv ~/ca.pem ~/kubernetes.pem ~/kubernetes-key.pem /etc/etcd
wget https://github.com/etcd-io/etcd/releases/download/v3.4.13/etcd-v3.4.13-linux-amd64.tar.gz
tar xvzf etcd-v3.4.13-linux-amd64.tar.gz
sudo mv etcd-v3.4.13-linux-amd64/etcd* /usr/local/bin/

create the Etcd systemd unit file by editing /etc/systemd/system/etcd.service

[Unit]
Description=etcd
Documentation=https://github.com/coreos

[Service]
ExecStart=/usr/local/bin/etcd \
--name 10.0.0.71 \
--cert-file=/etc/etcd/kubernetes.pem \
--key-file=/etc/etcd/kubernetes-key.pem \
--peer-cert-file=/etc/etcd/kubernetes.pem \
--peer-key-file=/etc/etcd/kubernetes-key.pem \
--trusted-ca-file=/etc/etcd/ca.pem \
--peer-trusted-ca-file=/etc/etcd/ca.pem \
--peer-client-cert-auth \
--client-cert-auth \
--initial-advertise-peer-urls https://10.0.0.71:2380 \
--listen-peer-urls https://10.0.0.71:2380 \
--listen-client-urls https://10.0.0.71:2379,http://127.0.0.1:2379 \
--advertise-client-urls https://10.0.0.71:2379 \
--initial-cluster-token etcd-cluster-0 \
--initial-cluster 10.0.0.71=https://10.0.0.71:2380,10.0.0.72=https://10.0.0.72:2380,10.0.0.73=https://10.0.0.73:2380 \
--initial-cluster-state new \
--data-dir=/var/lib/etcd
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target

Reload the daemon configuration, enable and start Etcd:

sudo systemctl daemon-reload
sudo systemctl enable etcd
sudo systemctl start etcd

Check it is running and clustered:
ETCDCTL_API=3 etcdctl member list
The output has to be like that:

25e141cd5630aead, started, 10.0.0.73, https://10.0.0.73:2380, https://10.0.0.73:2379, false
4e7196ec0c691986, started, 10.0.0.71, https://10.0.0.71:2380, https://10.0.0.71:2379, false
a02a3223c1119bbf, started, 10.0.0.72, https://10.0.0.72:2380, https://10.0.0.72:2379, false

Initialization of the master nodes

On the master nodes create a file config.yaml with the following content:

apiVersion: kubeadm.k8s.io/v1beta3
kind: ClusterConfiguration
kubernetesVersion: v1.29.3
controlPlaneEndpoint: "10.0.0.90:6443"
etcd:
external:
endpoints:
- https://10.0.0.71:2379
- https://10.0.0.72:2379
- https://10.0.0.73:2379
caFile: /etc/etcd/ca.pem
certFile: /etc/etcd/kubernetes.pem
keyFile: /etc/etcd/kubernetes-key.pem
networking:
podSubnet: 10.30.0.0/24
apiServer:
certSANs:
- "10.0.0.90"
extraArgs:
apiserver-count: "3"

Where 10.0.0.7x – our master nodes, 10.0.0.90 – certification authority (that is on HAproxy kubeapi load balancer VM), and 10.30.0.0/24 – subned for pods.

Copy file config.yaml to the other master nodes!

Initialise kubeadm on the first master node (10.0.0.71):
sudo kubeadm init --config=config.yaml

In case the preflight check is failing with the following message:

[init] Using Kubernetes version: v1.29.3
[preflight] Running pre-flight checks
error execution phase preflight: [preflight] Some fatal errors occurred:
[ERROR CRI]: container runtime is not running: output: time="2024-03-25T17:44:49Z" level=fatal msg="validate service connection: validate CRI v1 runtime API for endpoint \"unix:///var/run/containerd/containerd.sock\": rpc error: code = Unimplemented desc = unknown service runtime.v1.RuntimeService"
, error: exit status 1
[preflight] If you know what you are doing, you can make a check non-fatal with `--ignore-preflight-errors=...`

remove /etc/containerd/config.toml and restart containerd.service:

sudo rm /etc/containerd/config.toml
sudo systemctl restart containerd

it also may fail if the firewall restrictions in action, do the following:

sudo firewall-cmd --permanent --add-port=6443/tcp
sudo firewall-cmd --permanent --add-port=2379-2380/tcp
sudo firewall-cmd --permanent --add-port=10250/tcp
sudo firewall-cmd --permanent --add-port=10251/tcp
sudo firewall-cmd --permanent --add-port=10252/tcp
sudo firewall-cmd --permanent --add-port=10255/tcp
sudo firewall-cmd –reload

Once all the preflight checks are passed, the initialization should be performed well, repeat the kubeadm init as above.

Then we have to copy the certificates /etc/kubernetes/pki from the first (10.0.0.71) master node to two others.


sudo scp -r /etc/kubernetes/pki [email protected]:~
sudo scp -r /etc/kubernetes/pki [email protected]:~

On the second (master02, 10.0.0.72) and third (master03, 10.0.0.73) master nodes remove apiserver.crt and apiserver.key:
rm ./pki/apiserver.
and move the certificates to the /etc/kubernetes directory:
sudo mv ~/pki /etc/kubernetes/

Perform the same initialization of the rest of master nodes (master02 and master03) with the file config.yaml we copied previously from the first master node (master01):
sudo kubeadm init --config=config.yaml

By the initialization of the masters you will get the following message:

Your Kubernetes control-plane has initialized successfully!

To start using your cluster, you need to run the following as a regular user:

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

Alternatively, if you are the root user, you can run:

export KUBECONFIG=/etc/kubernetes/admin.conf

You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
https://kubernetes.io/docs/concepts/cluster-administration/addons/

You can now join any number of control-plane nodes by copying certificate authorities
and service account keys on each node and then running the following as root:

kubeadm join 10.0.0.90:6443 --token kzw57k.x5mitlly89nhobrd \
--discovery-token-ca-cert-hash sha256:d7f3b00c8b71c39f81d92227f32217c24d26f0f1e821c5151387be49ff7d1e05 \
--control-plane

Then you can join any number of worker nodes by running the following on each as root:

kubeadm join 10.0.0.90:6443 --token kzw57k.x5mitlly89nhobrd \
--discovery-token-ca-cert-hash sha256:d7f3b00c8b71c39f81d92227f32217c24d26f0f1e821c5151387be49ff7d1e05

Save the part that describes how to join nodes to the cluster.

By the following command you have to see all your 3 masters in the output:
kubectl get nodes
it should look like that:

NAME STATUS ROLES AGE VERSION
master01 NotReady control-plane 66m v1.29.1
master02 NotReady control-plane 46m v1.29.3
master03 NotReady control-plane 44m v1.29.3

and after some time

NAME STATUS ROLES AGE VERSION
master01 Ready control-plane 3h15m v1.29.1
master02 Ready control-plane 175m v1.29.3
master03 Ready control-plane 173m v1.29.3

To initialize the worker nodes, perform on each output you saved when it was initialization of master nodes:

kubeadm join 10.0.0.90:6443 --token kzw57k.x5mitlly89nhobrd \
--discovery-token-ca-cert-hash sha256:d7f3b00c8b71c39f81d92227f32217c24d26f0f1e821c5151387be49ff7d1e05

then you can check your nodes appeared in output of the kubectl get nodes command as previously masters nodes do.

Deploying the CNI to have the overlay network

In this example we will use Calico, but you are free to use any of existing ones.

Download and install the manifest:

curl https://calico-v3-25.netlify.app/archive/v3.25/manifests/calico.yaml -O
kubectl apply -f calico.yaml
kubectl get pods -n kube-system

Setting up the ingress controller

We will use the nginx ingress controller, but you are free to use any of exsiting ones.

git clone https://github.com/nginxinc/kubernetes-ingress.git --branch v3.4.3
cd kubernetes-ingress/
kubectl apply -f deployments/common/ns-and-sa.yaml
kubectl apply -f deployments/rbac/rbac.yaml
kubectl apply -f examples/shared-examples/default-server-secret/default-server-secret.yaml
kubectl apply -f deployments/common/nginx-config.yaml
kubectl apply -f deployments/common/ingress-class.yaml
kubectl apply -f deployments/daemon-set/nginx-ingress.yaml
kubectl get pods --namespace=nginx-ingress

That’s all folks!

Ранее публиковал записи о назначении определённому сетевому интерфейсу типа сети (общественная/частная/публичная), включение и отключение Windows Firewall, также опишу как разрешить пинг в брандмауэре Windows в командной строке.

Разрешаем ping для IPv4 в частной сети:

netsh advfirewall firewall add rule name="Allow ICMPv4" protocol=icmpv4:8,any dir=in action=allow profile=private

Разрешаем ping для IPv6 в публичной сети:

netsh advfirewall firewall add rule name="Allow ICMPv6" protocol=icmpv6:8,any dir=in action=allow profile=public

Разрешаем ping для IPv4 и IPv6 во всех сетях:
netsh advfirewall firewall add rule name="Allow ICMPv6" protocol=icmpv6:8,any dir=in action=allow profile=ALL

Также после profile= можно указать значение domain для доменной сети.

В посте указано, как изменить тип сети в Windows, теперь опишу как включить или отключить Firewall в командной строке для определённого типа сети (общественная/частная/доменная).

Выполняем от администратора выключение фаервола для частной сети:

netsh advfirewall set privateprofile state off

Аналогично выполняется отключение брандмауэра для общественной сети:

netsh advfirewall set publicprofile state off

Отключение Windows Firewall для доменной сети:

netsh advfirewall set domainprofile state off

 

Включение брандмауэра для частной сети:

netsh advfirewall set privateprofile state on

Включение Windows Firewall для общественной сети:

netsh advfirewall set publicprofile state on

Включение фаервола для доменной сети:

netsh advfirewall set domainprofile state on

 

В Powershell от администратора выполняем:

Get-NetConnectionProfile

Получаем список сетевых интерфейсов и их внутренние идентификаторы, интересует только значение InterfaceIndex:
InterfaceIndex : 13

Выполнем команду с подстановкой нужного значения после -InterfaceIndex (тот самый идентификатор, который получили выше) и указываем тип сети (Private/Public – Частные/Общедоступные):

Set-NetConnectionProfile -InterfaceIndex 13 -NetworkCategory Private

 

От этого зависит тип политик, применяемых Windows Firewall (брандмауэр).

Как-то мне пришла идея использовать обычный shared хостинг с PHP для того, чтобы создать прокси сервер (а через него уже можно и в интернет ходить, и скрэпперы/кроулеры использовать).

Для этого нам понадобится Nginx с PHP, подойдёт даже работающий на локальном компьютере или же локально на виртуальной машине, а также любой shared хостинг, который поддерживает PHP (5.6 и новее).

Работает эта схема следующим образом: Nginx выступает в роли самого proxy сервера, который указываем в качестве прокси в браузере, PHP в связке с этим Nginx занимается приёмом запросов от браузера (или скрэппера/кроулера) и отправляет его на shared хостинг, где мы должны разместить файл Proxy.php из репозитория https://github.com/zounar/php-proxy

Этот скрипт можно немного по-вкусу модифицировать, например убрать аутентификаицю на уровне заголовков, передаваемых в скрипт (но можно и оставить для секьюрности), в своём примере я убрал для сокращения описания шагов. Но настройку http basic аутентификацию в nginx опишу.

Здесь не буду объяснять, как устанавливать nginx, а также PHP-FPM.

Настраиваем виртуальный хост nginx следующим образом:

server {
listen 3128;
server_name _;
root /home/user/webproxy;
index index.php;

auth_basic "Restricted";
auth_basic_user_file /home/user/web/.htpasswd; #файл с хешированным паролем для http basic аутентификации

location ~ \.php$ {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
}

location / {
rewrite ^/(.*)$ /index.php?url=$host$uri; #здесь передаём все запросы нашего браузера/скрэппера/кроулера путём get в переменную url
}
}

Скрипт, который нужно положить в /home/webproxy/index.php:

<?php

$url = $_GET['url'];

$request = curl_init('http://your-shared-hosting.xyz/Proxy.php'); //путь к файлу на shared хостинге

curl_setopt($request, CURLOPT_HTTPHEADER, array(
'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:70.0) Gecko/20100101 Firefox/70.0',
'Proxy-Auth: SetInTheProxyPHPifEnabled',
'Proxy-Target-URL: https://'.$url
));

curl_exec($request);

?>

 

Менять можно по своему вкусу для сокрытия такого очевидного использования.

От хостинга требуется чтобы в PHP была поддержка libcurl, gzip и PHP safe_mode disabled (практически любой хостинг).

function returnStatus(req, status) {
//console.log(req);
if(status == 200) {
console.log("The url is available");
// send an event
}
else {
console.log("The url returned status code " + status);
// send a different event
}
}

function fetchStatus(address) {
var client = new XMLHttpRequest();
client.onreadystatechange = function() {
// in case of network errors this might not give reliable results
if(this.readyState == 4)
returnStatus(this, this.status);
}
client.open(“HEAD”, address);
client.send();
}


fetchStatus("/");

 

В практике возникла задача удалить записи, созданные ранее определённой даты. Естественно, дата — это одно из полей таблицы.

Таким образом можно проверить какие записи будут удалены:
SELECT * FROM tablename WHERE date < DATE_SUB(NOW(), INTERVAL 385 DAY);

Удалить записи, которые были созданы ранее 385 дней назад:
DELETE FROM tablename WHERE date < DATE_SUB(NOW(), INTERVAL 385 DAY);

Создаём в корне сайта out.php

В неё внутри PHP-тегов пишем такой код:

    if ((isset($_GET['link'])) AND (preg_match( '/^(http|https)://[a-z0-9]+([-.]{1}[a-z0-9]+)*.[a-z]{2,5}'.'((:[0-9]{1,5})?/.*)?$/i' ,$_GET['link']))){
        header("Location: ".$_GET['link']."");
    }

После сохранения, заменяем все ссылки на сайте на подобные: /out.php?link-http://itblog.pp.ua. Это позволяет поисковым системам не считать эти ссылки за внешние, тем самым повышает, а точнее не снижает тИЦ и PR сайта.