5.3 KiB
5.3 KiB
Deploying a VM and exposing it over a Gateway Prefix
Table of Contents
- Introduction
- Example code
- Detailed explanation
- Deploying a VM and exposing it over a Gateway using a Full domain
- Example code
- Detailed explanation
Introduction
After the deployment of a VM, now it's time to expose it to the world
Example code
import { FilterOptions, GatewayNameModel } from "../src";
import { getClient } from "./client_loader";
import { log } from "./utils";
// read more about the gateway types in this doc: https://github.com/threefoldtech/zos/tree/main/docs/gateway
async function main() {
const grid3 = await getClient();
const gatewayQueryOptions: FilterOptions = {
gateway: true,
farmId: 1,
};
const gw = new GatewayNameModel();
gw.name = "test";
gw.node_id = +(await grid3.capacity.filterNodes(gatewayQueryOptions))[0].nodeId;
gw.tls_passthrough = false;
// the backends have to be in this format `http://ip:port` or `https://ip:port`, and the `ip` pingable from the node so using the ygg ip or public ip if available.
gw.backends = ["http://185.206.122.35:8000"];
// deploy
const res = await grid3.gateway.deploy_name(gw);
log(res);
// get the deployment
const l = await grid3.gateway.getObj(gw.name);
log(l);
// // delete
// const d = await grid3.gateway.delete_name({ name: gw.name });
// log(d);
grid3.disconnect();
}
main();
Detailed explanation
const gw = new GatewayNameModel();
gw.name = "test";
gw.node_id = +(await grid3.capacity.filterNodes(gatewayQueryOptions))[0].nodeId;
gw.tls_passthrough = false;
gw.backends = ["http://185.206.122.35:8000"];
- we created a gateway name model and gave it a
name-that's why it's called GatewayName-testto be deployed on gateway node to end up with a domaintest.gent01.devnet.grid.tf, - we create a proxy for the gateway to send the traffic coming to
test.ghent01.devnet.grid.tfto the backendhttp://185.206.122.35, we saytls_passthrough is falseto let the gateway terminate the traffic, if you replace it withtrueyour backend service needs to be able to do the TLS termination
deploying
// deploy
const res = await grid3.gateway.deploy_name(gw);
log(res);
this deploys GatewayName on the grid
getting deployment object
const l = await grid3.gateway.getObj(gw.name);
log(l);
getting the deployment information can be done using getObj
deletion
const d = await grid3.gateway.delete_name({ name: gw.name });
log(d);
Deploying a VM and exposing it over a Gateway using a Full domain
After the deployment of a VM, now it's time to expose it to the world
Example code
import { FilterOptions, GatewayFQDNModel } from "../src";
import { getClient } from "./client_loader";
import { log } from "./utils";
// read more about the gateway types in this doc: https://github.com/threefoldtech/zos/tree/main/docs/gateway
async function main() {
const grid3 = await getClient();
const gatewayQueryOptions: FilterOptions = {
gateway: true,
farmId: 1,
};
const gw = new GatewayFQDNModel();
gw.name = "applyFQDN";
gw.node_id = +(await grid3.capacity.filterNodes(gatewayQueryOptions))[0].nodeId;
gw.fqdn = "test.hamada.grid.tf";
gw.tls_passthrough = false;
// the backends have to be in this format `http://ip:port` or `https://ip:port`, and the `ip` pingable from the node so using the ygg ip or public ip if available.
gw.backends = ["http://185.206.122.35:8000"];
// deploy
const res = await grid3.gateway.deploy_fqdn(gw);
log(res);
// get the deployment
const l = await grid3.gateway.getObj(gw.name);
log(l);
// // delete
// const d = await grid3.gateway.delete_fqdn({ name: gw.name });
// log(d);
grid3.disconnect();
}
main();
Detailed explanation
const gw = new GatewayFQDNModel();
gw.name = "applyFQDN";
gw.node_id = 1;
gw.fqdn = "test.hamada.grid.tf";
gw.tls_passthrough = false;
gw.backends = ["my yggdrasil IP"];
- we created a
GatewayFQDNModeland gave it a nameapplyFQDNNto be deployed on gateway node1and specified the fully qualified domainfqdnto a domain we owntest.hamada.grid.tf - we created a record on our name provider for
test.hamada.grid.tfto point to the IP of gateway node1 - we specified the backened would be an yggdrassil ip so once this is deployed when we go to
test.hamada.grid.tfwe go to the gateway server and from their our traffic goes to the backend.
deploying
// deploy
const res = await grid3.gateway.deploy_fqdn(gw);
log(res);
this deploys GatewayName on the grid
get deployment object
const l = await grid3.gateway.getObj(gw.name);
log(l);
getting the deployment information can be done using getObj
deletion
const d = await grid3.gateway.delete_fqdn({ name: gw.name });
log(d);