underpost 2.8.787 → 2.8.791
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/cli.md +21 -13
- package/docker-compose.yml +1 -1
- package/manifests/lxd/lxd-admin-profile.yaml +1 -0
- package/manifests/lxd/underpost-setup.sh +52 -2
- package/package.json +1 -1
- package/src/cli/cluster.js +0 -3
- package/src/cli/index.js +10 -0
- package/src/cli/lxd.js +50 -1
- package/src/index.js +1 -1
package/README.md
CHANGED
package/cli.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
## underpost ci/cd cli v2.8.
|
|
1
|
+
## underpost ci/cd cli v2.8.791
|
|
2
2
|
|
|
3
3
|
### Usage: `underpost [options] [command]`
|
|
4
4
|
```
|
|
@@ -475,18 +475,26 @@ Options:
|
|
|
475
475
|
Lxd management
|
|
476
476
|
|
|
477
477
|
Options:
|
|
478
|
-
--init
|
|
479
|
-
--reset
|
|
480
|
-
--install
|
|
481
|
-
--dev
|
|
482
|
-
--create-virtual-network
|
|
483
|
-
--create-admin-profile
|
|
484
|
-
--control
|
|
485
|
-
--
|
|
486
|
-
--
|
|
487
|
-
--
|
|
488
|
-
--
|
|
489
|
-
-
|
|
478
|
+
--init Init lxd
|
|
479
|
+
--reset Reset lxd on current machine
|
|
480
|
+
--install Install lxd on current machine
|
|
481
|
+
--dev Set dev context env
|
|
482
|
+
--create-virtual-network Create lxd virtual network bridge
|
|
483
|
+
--create-admin-profile Create admin profile for lxd management
|
|
484
|
+
--control set control node vm context
|
|
485
|
+
--worker set worker node context
|
|
486
|
+
--create-vm <vm-id> Create default virtual machines
|
|
487
|
+
--init-vm <vm-id> Get init vm underpost script
|
|
488
|
+
--info-vm <vm-id> Get all info vm
|
|
489
|
+
--root-size <gb-size> Set root size vm
|
|
490
|
+
--join-node <nodes> Comma separated worker and control node e.
|
|
491
|
+
g. k8s-worker-1,k8s-control
|
|
492
|
+
--expose <vm-name-ports> Vm name and : separated with Comma separated
|
|
493
|
+
vm port to expose e. g. k8s-control:80,443
|
|
494
|
+
--delete-expose <vm-name-ports> Vm name and : separated with Comma separated
|
|
495
|
+
vm port to remove expose e. g.
|
|
496
|
+
k8s-control:80,443
|
|
497
|
+
-h, --help display help for command
|
|
490
498
|
|
|
491
499
|
```
|
|
492
500
|
|
package/docker-compose.yml
CHANGED
|
@@ -27,6 +27,11 @@ resize2fs /dev/sda2
|
|
|
27
27
|
echo "Disk and filesystem resized successfully."
|
|
28
28
|
sudo dnf install -y tar
|
|
29
29
|
sudo dnf install -y bzip2
|
|
30
|
+
sudo dnf install -y git
|
|
31
|
+
sudo dnf -y update
|
|
32
|
+
sudo dnf -y install epel-release
|
|
33
|
+
sudo dnf install -y ufw
|
|
34
|
+
sudo systemctl enable --now ufw
|
|
30
35
|
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
|
|
31
36
|
NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
|
|
32
37
|
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
|
|
@@ -77,17 +82,62 @@ echo "USE_WORKER = $USE_WORKER"
|
|
|
77
82
|
underpost cluster --kubeadm
|
|
78
83
|
underpost cluster --reset
|
|
79
84
|
|
|
85
|
+
PORTS=(
|
|
86
|
+
22 # SSH
|
|
87
|
+
80 # HTTP
|
|
88
|
+
443 # HTTPS
|
|
89
|
+
53 # DNS (TCP/UDP)
|
|
90
|
+
66 # TFTP
|
|
91
|
+
67 # DHCP
|
|
92
|
+
69 # TFTP
|
|
93
|
+
111 # rpcbind
|
|
94
|
+
179 # Calico BGP
|
|
95
|
+
2049 # NFS
|
|
96
|
+
20048 # NFS mountd
|
|
97
|
+
4011 # PXE boot
|
|
98
|
+
5240 # snapd API
|
|
99
|
+
5248 # Juju controller
|
|
100
|
+
6443 # Kubernetes API
|
|
101
|
+
9153 # CoreDNS metrics
|
|
102
|
+
10250 # Kubelet API
|
|
103
|
+
10251 # kube-scheduler
|
|
104
|
+
10252 # kube-controller-manager
|
|
105
|
+
10255 # Kubelet read-only (deprecated)
|
|
106
|
+
10257 # controller-manager (v1.23+)
|
|
107
|
+
10259 # scheduler (v1.23+)
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
PORT_RANGES=(
|
|
111
|
+
2379:2380 # etcd
|
|
112
|
+
# 30000:32767 # NodePort range
|
|
113
|
+
# 3000:3100 # App node ports
|
|
114
|
+
32765:32766 # Ephemeral ports
|
|
115
|
+
6783:6784 # Weave Net
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
# Open individual ports
|
|
119
|
+
for PORT in "${PORTS[@]}"; do
|
|
120
|
+
ufw allow ${PORT}/tcp
|
|
121
|
+
ufw allow ${PORT}/udp
|
|
122
|
+
done
|
|
123
|
+
|
|
124
|
+
# Open port ranges
|
|
125
|
+
for RANGE in "${PORT_RANGES[@]}"; do
|
|
126
|
+
ufw allow ${RANGE}/tcp
|
|
127
|
+
ufw allow ${RANGE}/udp
|
|
128
|
+
done
|
|
129
|
+
|
|
80
130
|
# Behavior based on flags
|
|
81
131
|
if $USE_KUBEADM; then
|
|
82
132
|
echo "Running control node with kubeadm..."
|
|
83
133
|
underpost cluster --kubeadm
|
|
84
|
-
kubectl get pods --all-namespaces -o wide -w
|
|
134
|
+
# kubectl get pods --all-namespaces -o wide -w
|
|
85
135
|
fi
|
|
86
136
|
|
|
87
137
|
if $USE_KIND; then
|
|
88
138
|
echo "Running control node with kind..."
|
|
89
139
|
underpost cluster
|
|
90
|
-
kubectl get pods --all-namespaces -o wide -w
|
|
140
|
+
# kubectl get pods --all-namespaces -o wide -w
|
|
91
141
|
fi
|
|
92
142
|
|
|
93
143
|
if $USE_WORKER; then
|
package/package.json
CHANGED
package/src/cli/cluster.js
CHANGED
|
@@ -475,9 +475,6 @@ Allocatable:
|
|
|
475
475
|
return resources;
|
|
476
476
|
},
|
|
477
477
|
initHost() {
|
|
478
|
-
// Base
|
|
479
|
-
shellExec(`sudo dnf -y update`);
|
|
480
|
-
shellExec(`sudo dnf -y install epel-release`);
|
|
481
478
|
// Install docker
|
|
482
479
|
shellExec(`sudo dnf -y install dnf-plugins-core
|
|
483
480
|
sudo dnf config-manager --add-repo https://download.docker.com/linux/rhel/docker-ce.repo`);
|
package/src/cli/index.js
CHANGED
|
@@ -279,10 +279,20 @@ program
|
|
|
279
279
|
.option('--create-virtual-network', 'Create lxd virtual network bridge')
|
|
280
280
|
.option('--create-admin-profile', 'Create admin profile for lxd management')
|
|
281
281
|
.option('--control', 'set control node vm context')
|
|
282
|
+
.option('--worker', 'set worker node context')
|
|
282
283
|
.option('--create-vm <vm-id>', 'Create default virtual machines')
|
|
283
284
|
.option('--init-vm <vm-id>', 'Get init vm underpost script')
|
|
284
285
|
.option('--info-vm <vm-id>', 'Get all info vm')
|
|
285
286
|
.option('--root-size <gb-size>', 'Set root size vm')
|
|
287
|
+
.option('--join-node <nodes>', 'Comma separated worker and control node e. g. k8s-worker-1,k8s-control')
|
|
288
|
+
.option(
|
|
289
|
+
'--expose <vm-name-ports>',
|
|
290
|
+
'Vm name and : separated with Comma separated vm port to expose e. g. k8s-control:80,443',
|
|
291
|
+
)
|
|
292
|
+
.option(
|
|
293
|
+
'--delete-expose <vm-name-ports>',
|
|
294
|
+
'Vm name and : separated with Comma separated vm port to remove expose e. g. k8s-control:80,443',
|
|
295
|
+
)
|
|
286
296
|
.description('Lxd management')
|
|
287
297
|
.action(UnderpostLxd.API.callback);
|
|
288
298
|
|
package/src/cli/lxd.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { getNpmRootPath } from '../server/conf.js';
|
|
2
|
+
import { getLocalIPv4Address } from '../server/dns.js';
|
|
2
3
|
import { pbcopy, shellExec } from '../server/process.js';
|
|
4
|
+
import fs from 'fs-extra';
|
|
3
5
|
|
|
4
6
|
class UnderpostLxd {
|
|
5
7
|
static API = {
|
|
@@ -16,6 +18,9 @@ class UnderpostLxd {
|
|
|
16
18
|
createVm: '',
|
|
17
19
|
infoVm: '',
|
|
18
20
|
rootSize: '',
|
|
21
|
+
joinNode: '',
|
|
22
|
+
expose: '',
|
|
23
|
+
deleteExpose: '',
|
|
19
24
|
},
|
|
20
25
|
) {
|
|
21
26
|
const npmRoot = getNpmRootPath();
|
|
@@ -28,7 +33,11 @@ class UnderpostLxd {
|
|
|
28
33
|
if (options.init === true) {
|
|
29
34
|
shellExec(`sudo systemctl start snap.lxd.daemon`);
|
|
30
35
|
shellExec(`sudo systemctl status snap.lxd.daemon`);
|
|
31
|
-
|
|
36
|
+
const lxdPressedContent = fs
|
|
37
|
+
.readFileSync(`${underpostRoot}/manifests/lxd/lxd-preseed.yaml`, 'utf8')
|
|
38
|
+
.replaceAll(`127.0.0.1`, getLocalIPv4Address());
|
|
39
|
+
// shellExec(`lxd init --preseed < ${underpostRoot}/manifests/lxd/lxd-preseed.yaml`);
|
|
40
|
+
shellExec(`echo "${lxdPressedContent}" | lxd init --preseed`);
|
|
32
41
|
shellExec(`lxc cluster list`);
|
|
33
42
|
}
|
|
34
43
|
if (options.createVirtualNetwork === true) {
|
|
@@ -56,17 +65,57 @@ ipv6.address=none`);
|
|
|
56
65
|
let flag = '';
|
|
57
66
|
if (options.control === true) {
|
|
58
67
|
flag = ' -s -- --kubeadm';
|
|
68
|
+
shellExec(`lxc exec ${options.initVm} -- bash -c 'mkdir -p /home/dd/engine'`);
|
|
69
|
+
shellExec(`lxc file push /home/dd/engine/engine-private ${options.initVm}/home/dd/engine --recursive`);
|
|
59
70
|
} else if (options.worker == true) {
|
|
60
71
|
flag = ' -s -- --worker';
|
|
61
72
|
}
|
|
62
73
|
pbcopy(`cat ${underpostRoot}/manifests/lxd/underpost-setup.sh | lxc exec ${options.initVm} -- bash${flag}`);
|
|
63
74
|
}
|
|
75
|
+
if (options.joinNode && typeof options.joinNode === 'string') {
|
|
76
|
+
const [workerNode, controlNode] = options.joinNode.split(',');
|
|
77
|
+
const token = shellExec(
|
|
78
|
+
`echo "$(lxc exec ${controlNode} -- bash -c 'sudo kubeadm token create --print-join-command')"`,
|
|
79
|
+
{ stdout: true },
|
|
80
|
+
);
|
|
81
|
+
shellExec(`lxc exec ${workerNode} -- bash -c '${token}'`);
|
|
82
|
+
}
|
|
64
83
|
if (options.infoVm && typeof options.infoVm === 'string') {
|
|
65
84
|
shellExec(`lxc config show ${options.infoVm}`);
|
|
66
85
|
shellExec(`lxc info --show-log ${options.infoVm}`);
|
|
67
86
|
shellExec(`lxc info ${options.infoVm}`);
|
|
68
87
|
shellExec(`lxc list ${options.infoVm}`);
|
|
69
88
|
}
|
|
89
|
+
if (options.expose && typeof options.expose === 'string') {
|
|
90
|
+
const [controlNode, ports] = options.expose.split(':');
|
|
91
|
+
console.log({ controlNode, ports });
|
|
92
|
+
const protocols = ['tcp']; // udp
|
|
93
|
+
const hostIp = getLocalIPv4Address();
|
|
94
|
+
// The vmIp will now be the static IP assigned in the admin-profile
|
|
95
|
+
const vmIp = shellExec(
|
|
96
|
+
`lxc list ${controlNode} --format json | jq -r '.[0].state.network.enp5s0.addresses[] | select(.family=="inet") | .address'`,
|
|
97
|
+
{ stdout: true },
|
|
98
|
+
).trim();
|
|
99
|
+
for (const port of ports.split(',')) {
|
|
100
|
+
for (const protocol of protocols) {
|
|
101
|
+
shellExec(`lxc config device remove ${controlNode} ${controlNode}-${protocol}-port-${port}`);
|
|
102
|
+
shellExec(
|
|
103
|
+
`lxc config device add ${controlNode} ${controlNode}-${protocol}-port-${port} proxy listen=${protocol}:${hostIp}:${port} connect=${protocol}:${vmIp}:${port} nat=true`,
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (options.deleteExpose && typeof options.deleteExpose === 'string') {
|
|
109
|
+
const [controlNode, ports] = options.deleteExpose.split(':');
|
|
110
|
+
console.log({ controlNode, ports });
|
|
111
|
+
const protocols = ['tcp']; // udp
|
|
112
|
+
for (const port of ports.split(',')) {
|
|
113
|
+
for (const protocol of protocols) {
|
|
114
|
+
// The device name is consistent: {controlNode}-port-{port}
|
|
115
|
+
shellExec(`lxc config device remove ${controlNode} ${controlNode}-${protocol}-port-${port}`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
70
119
|
},
|
|
71
120
|
};
|
|
72
121
|
}
|