简体   繁体   English

Python Azure SDK:在同一个云服务中创建多个VM

[英]Python Azure SDK: create multiple VMs in the same cloud service

I am trying to create multiple VMs in the same cloud service (but in unique deployments within the cloud service). 我正在尝试在同一云服务中创建多个VM(但在云服务中的唯一部署中)。 The below produces only one machine which will have the name mycluster-master-3 (given self.numMasters == 3). 下面仅产生一台名称为mycluster-master-3的机器(给定self.numMasters == 3)。 In other words, only the last machine is actually created and can be seen in Azure management portal. 换句话说,只有最后一台计算机实际创建,并且可以在Azure管理门户中看到。 Note that there are no errors when I execute this code with self.numMasters == 3: 请注意,使用self.numMasters == 3执行此代码时没有错误:

for node in range(self.numMasters):
            logger.info('Deploying virtual machine "%s"...' % (self.clusterName + '-master-' + str(node + 1)))
            logger.info('Creating linuxConfig...')
            linuxConfig = azure.servicemanagement.LinuxConfigurationSet(
                host_name=self.clusterName + '-master-' + str(node + 1),
                user_name='auser',
                user_password='Auser123!',
                disable_ssh_password_authentication=True
            )
            # Destination storage account container/blob where the VM disk
            # will be created
            media_link = 'https://xxxxxxx.blob.core.windows.net/xxxxxx/%s.vhd' % (self.clusterName + '-master-' + str(node + 1))
            os_hd = azure.servicemanagement.OSVirtualHardDisk(image_name, media_link)
            logger.info('Creating virtual machine deployment...')
            self.sms.create_virtual_machine_deployment(
                service_name=serviceName,
                deployment_name=self.clusterName + '-master-' + str(node + 1),
                label=self.clusterName + '-master-' + str(node + 1),
                role_name=self.clusterName + '-master-' + str(node + 1),
                system_config=linuxConfig,
                os_virtual_hard_disk=os_hd,
                role_size=self.instanceType,
                deployment_slot='production'
            )

I thought having all my VMs in one cloud service would allow them to talk to each other internally without being exposed to machines in my other cloud services. 我以为,将所有VM都集成在一个云服务中,可以使它们在内部相互通信,而不会暴露给我其他云服务中的计算机。 But apparently, a cloud service provides a single public IP to VM within it. 但是很显然,云服务向其中的VM提供了单个公共IP。 Perhaps that's why only one VM is created, although, conceptually, I thought a single cloud service can have multiple VM instances. 也许这就是为什么仅创建一个VM的原因,尽管从概念上讲,我认为单个云服务可以具有多个VM实例。 This confuses the hell out of me. 这使我感到困惑。 So now I am thinking that I need to have one cloud service for each VM instance in my cluster. 因此,现在我想为集群中的每个VM实例都需要一个云服务。 This way, all of the machines will have a public IP and can be accessed over the internet. 这样,所有机器都将具有公共IP,并且可以通过Internet访问。 I also need to put all the cloud services within a virtual network. 我还需要将所有云服务放在虚拟网络中。 That way, traffic between them will not be routed through internet. 这样,它们之间的流量将不会通过Internet路由。 Is my assumption correct? 我的假设正确吗? Is there a better/other way to accomplish what I want (a cluster of machines talking to each other securely and fast, yet be SSH-able through internet.) 是否有更好/其他的方式来实现我想要的功能(一簇机器彼此安全,快速地进行通信,但可以通过Internet进行SSH连接)。

First of all - if you are creating a cluster, do not put the VMs in separate Cloud Services. 首先-如果要创建集群,请不要将VM放在单独的Cloud Services中。 Please read thouroughly this article: Manage the availbility of Virtual Mchines . 请仔细阅读以下文章: 管理虚拟机的可用性

Then to the main topic: multiple VMs can and should be deployed into same Cloud Service when they serve common purpose (building a cluster). 然后是主要主题:当多个VM出于共同目的(构建集群)时, 可以并且应该将多个VM部署到同一个Cloud Service中。

VMs in same Cloud service can talk to each other without going to Internet and without need for you to do something special, beside opening FireWalls on the VMs themselfs. 同一Cloud服务中的VM 可以相互通信,而无需访问Internet,也不需要您做一些特殊的事情,除了自己在VM上打开FireWalls。

For how the name resolution works in Azure as a whole, you can read the following article: Name resolution for VM and role instances . 有关名称解析在整个Azure中的工作方式,您可以阅读以下文章: VM和角色实例的名称解析

One VIP per Cloud service - this is so. 每个云服务一个VIP-就是这样。 But why should that be an issue? 但是,为什么这是一个问题? Please elaborate on the reason for you to require multiple VIP (Public IP Addresses) for the single Cloud Service (your cluster). 请详细说明您为单个Cloud Service(您的集群)要求多个VIP(公共IP地址)的原因。 The following article will give you an idea about different options for Load Balancing your clustered VMs: Load Balancing for Virtual Machines . 以下文章将为您提供有关群集虚拟机负载平衡的不同选项的想法: 虚拟机的负载平衡

On how to configure SSH for per-VM access, you can create Endpoints for your VMs with different Public Ports . 关于如何为每个VM访问配置SSH,您可以为具有不同Public Port的 VM 创建端点

Last, but not least, the reasony why you end up with only one VM created. 最后但并非最不重要的一点是,您最终只能创建一个VM的原因。 You can only create one VM in Cloud Service at a time . 您一次只能在Cloud Service 创建一个VM。 You cannot create second VM in same cloud service while the first one is still being created. 您仍无法在第一个虚拟机中创建第二个虚拟机。 So, the creation of VM1 should be 100% complete, then you can create second VM in same Cloud Service. 因此,VM1的创建应100%完成,然后您可以在同一Cloud Service中创建第二个VM。

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

相关问题 Azure Python SDK - 列出 VM 并生成自定义 JSON 响应 - Azure Python SDK - list VMs and generate custom JSON response 使用Azure Python SDK打印资源组中的VM列表 - Printing list of VMs in a Resource Group with Azure Python SDK Azure Python SDK:如何在VM上设置自动关闭任务? - Azure Python SDK: How to set auto-shutdown task on VMs? 如何在azure上的同一个云服务中部署多台计算机 - How to deploy Multiple machines in the same cloud service on azure python代码在多个ESXi主机和VM上启动ntp服务 - python code to start ntp service on multiple ESXi hosts and VMs How create/delete secrets of Azure service principal by using another service principal with REST API or Python SDK? - How create/delete secrets of Azure service principal by using another service principal with REST API or Python SDK? 在Azure上向同一云服务添加新角色 - add new role to the same cloud service on azure 如何在列出所有 VM 时在 Azure Python SDK 中使用 nextLink 属性 - How to use nextLink property in Azure Python SDK while listing all VMs 使用libcloud在azure上创建VM或云服务? - Create a vm or cloud service on azure using libcloud? Python Cloud Service中的Azure环境变量 - Azure Environment Variables in Python Cloud Service
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM