node.js - 将谷歌云中的外部 IP 地址设置为我保留的静态地址
问题描述
我最近开始使用谷歌云并构建了一个节点应用程序,以根据我设置的图像自动部署实例。
该脚本运行良好,我遇到的唯一问题是我似乎无法分配我使用配置保留的静态 IP 地址,我是节点和谷歌云的新手,并且不确定我做错了什么。
任何帮助或指导将不胜感激
我的配置看起来像:
const config = {
machineType: 'e2-micro',
http:true,
https:true,
networkInterfaces: [
{
accessConfigs: [
{
type: 'ONE_TO_ONE_NAT',
name: 'External NAT',
natIP: '0.0.0.0',// this is an ip address that is passed into this as a variable in that format(it is not a scope issue)
setPublicPtr: false,
networkTier: 'PREMIUM', //ip address is reserved using this network tier as well
}
],
kind: 'compute#networkInterface'
}],
disks: [
{
boot: true,
initializeParams: {
sourceImage:
'https://www.googleapis.com/compute/v1/projects' +
'/myproject/global/images/devimage'
}
}
],
metadata: {
items: [
{
key: 'startup-script',
value: 'sudo node index.js'
}
],
kind: 'compute#metadata'
},
};
解决方案
请注意,到目前为止,还没有办法通过Google API将静态 IP 分配给现有的Compute Engine 实例。
为了对现有的 Compute Engine 实例执行此操作,您需要使用Google Cloud 控制台或 Cloud SDK。
但是,要将静态 IP 分配给新的 Compute Engine 实例,您确实可以通过 API 通过类似于以下的请求来执行此操作:
{
"name": "INSTANCE_NAME",
"machineType": "zones/ZONE/machineTypes/MACHINE_TYPE",
"networkInterfaces": [{
"accessConfigs": [{
"type": "ONE_TO_ONE_NAT",
"name": "External NAT",
"natIP": "IP_ADDRESS"
}],
"network": "global/networks/default"
}],
"disks": [{
"autoDelete": "true",
"boot": "true",
"type": "PERSISTENT",
"initializeParams": {
"sourceImage": "projects/debian-cloud/global/images/v20150818"
}
}]
}
在这种情况下,在创建新实例并分配 IP 地址时,可能未提供实例名称。
推荐阅读
- windows - Psql命令行密码和查询
- sql - 如何在 Postgres 中对列求和
- node.js - res.set('Content-Type','image/jpg') 在节点 js 中提供图像时不起作用
- python-3.x - Python 假期模块:自定义假期未包含在“已观察”中
- mysql - 如果元素包含SQL列表中的所有数据,如何选择id?
- python - 如何检查是否有人投票给了不和谐机器人 discord.py
- hazelcast - Hazelcast 管理中心队列统计
- tensorflow-serving - 使用 Tensorflow Serving 为多个模型提供服务时,Prometheus 指标上的标签
- c# - Unity sprite 翻转超出相机范围
- r - 同一张图中的两个馅饼 - Highcharter