简体   繁体   English

将域名服务器添加到 Google Container Optimized OS

[英]Adding Domain Nameserver into Google Container Optimized OS

I would like to prepend our own domain nameserver into COS. How should I do it?我想把我们自己的域名服务器添加到 COS 中,我该怎么做?

Is it just create the folowing in /etc/dhcp/dhclient.conf :它只是在/etc/dhcp/dhclient.conf中创建以下内容:

  prepend domain-name-servers <domain ip>;

I have added the above configuration but I still not able to use my domain in the COS VM instance.我已经添加了上述配置,但我仍然无法在 COS VM 实例中使用我的域。 Is there something I've missed?有什么我错过的吗?

How do I restart the network adapter in COS without reseting/rebooting?如何在不重置/重启的情况下重启 COS 中的网络适配器?

COS uses "cloud-init". COS 使用“cloud-init”。 If you want to add dns server as configs like this to COS, you'd use cloud-init as a way to configure your instance when it boots up.如果您想将 dns 服务器作为这样的配置添加到 COS,您可以使用 cloud-init 作为实例启动时配置实例的一种方式。 The cloud-init tool expects its configuration in the value of the user-data key of the instance metadata. cloud-init 工具期望其配置在实例元数据的用户数据键的值中。 For more information1更多信息1

To pass the configurations of cloud-init to the instance, you need to create your instance with the flag: --metadata-from-file user-data=[filename], or add the user-data=[filename] key value pair to the instance from the console, where the file would be stored on an external location like cloud storage, to which you'd provide the URL.要将 cloud-init 的配置传递给实例,您需要使用以下标志创建实例:--metadata-from-file user-data=[filename],或者添加 user-data=[filename] 键值对从控制台到实例,文件将存储在云存储等外部位置,您将向该位置提供 URL。 It's also possible to just copy the config into the value section when setting the metadata.在设置元数据时,也可以将配置复制到 value 部分。 Example configurations to specify name servers and domains can be found in the following link .可以在以下链接中找到指定名称服务器和域的示例配置。

By replacing the yaml config value in metadata (but keeping the "user-data" key) with the following config, you can configure resolv.conf to use custom name servers and get the instance to use those name servers for address resolution.通过将元数据中的 yaml 配置值(但保留“user-data”键)替换为以下配置,您可以将 resolv.conf 配置为使用自定义名称服务器并让实例使用这些名称服务器进行地址解析。

As an example you can create a file called cloud-config-resolv containing the following:例如,您可以创建一个名为 cloud-config-resolv 的文件,其中包含以下内容:

#cloud-config

write_files:
- path: /etc/systemd/resolved.conf
permissions: "0644"
owner: root:root
content: |
# This is my custom resolv.conf!
[Resolve]
DNS= 8.8.8.8 (Use your IP)

runcmd:
- ['systemctl', 'restart', 'systemd-resolved']

You can then run the following command to add [Your-IP] to the resolv.conf.然后,您可以运行以下命令将 [Your-IP] 添加到 resolv.conf。

gcloud compute instances create instance-name \
--image-family cos-stable \
--image-project cos-cloud \
--metadata-from-file user-data=cloud-config-resolv \
--zone us-central1-a

I'm not confirmed that it will persist after 24hrs as dhcp lease is renewed and any changes are cleared.我没有确认它会在 24 小时后持续存在,因为 dhcp 租约已更新并且所有更改都已清除。 But the file does persist through network daemon restarts and VM restarts.但是该文件确实会通过网络守护程序重新启动和 VM 重新启动而持续存在。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Google Container Optimized OS中的工具箱进行配管 - Piping using toolbox in Google Container Optimized OS 谷歌容器优化操作系统中的二进制安装 - binary install in google container optimized OS 在 GCP 上的 Google 容器优化操作系统上禁用容器自动启动 - Disable Container Auto Launch on Google Container Optimized OS on GCP 在 Google Cloud Container Optimized OS (COS) 中安装 gcsfuse - Install gcsfuse in Google Cloud Container Optimized OS (COS) 在 Google Cloud VM 中将 GPU 与容器和容器优化操作系统一起使用 - Using GPU with containers and Container Optimized OS in Google Cloud VM 在 GCP 中使用 Google 容器优化操作系统时的任何许可费用 - Any license cost when Google container optimized OS in GCP Google Cloud Container Optimized OS 主机日志到 stackdriver - Google Cloud Container Optimized OS host logs to stackdriver 无法在 Google Container-Optimized OS 上运行可执行的 shell 脚本 - Cannot run executable shell script on Google Container-Optimized OS 如何对具有 Google 容器优化操作系统的计算实例使用操作系统补丁管理? - How to use OS patch management for compute instances with Google container optimized os? 如何使用 Terraform 在 Google Cloud Container Optimized OS 下执行脚本(remote-exec) - How to execute scripts (remote-exec) under Google Cloud Container Optimized OS using Terraform
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM