0

Need to copy a local file (ad-hoc or during a release process) into a VMSS/Node or at least the VMSS's attached disk.

How can you copy a local file into a remote directory location on the VMSS/Node? Specifically from the command-line so that it can happen in a release pipeline (PowerShell etc).

I've read examples of using SCP but with no information on how to specifically do this with a VMSS in Azure. username@hostname doesn't really apply here or am I missing something?

I imagine every time it scales, the file previously copied will be available in every VM so this does not need to happen on every scale event?

BrutalDev
  • 6,181
  • 6
  • 58
  • 72

1 Answers1

0

You can set up SSH to an AKS node as detailed here using a privileged container pod. Once you have SSH-d into the node, in case of Linux nodes, from a different terminal shell you can copy files from your local machine to the AKS node using:

kubectl get pods
NAME                                                    READY   STATUS    RESTARTS   AGE
node-debugger-aks-nodepool1-xxxxxxxx-vmssxxxxxx-xxxxx   1/1     Running   0          21s

kubectl cp /source/path node-debugger-aks-nodepoolname-xxxxxxxx-vmssxxxxxx-xxxxx:/host/path/to/destination

[Note: In the destination please remember to prepend the desired destination path on the host with /host]

In case of Windows nodes, once the SSH connection is set up as detailed here, you can copy files from your local machine to the Windows node using:

scp -o 'ProxyCommand ssh -p 2022 -W %h:%p azureuser@127.0.0.1' /source/path azureuser@<node-private-IP>:/path/to/destination

Reference for kubectl cp command


I imagine every time it scales, the file previously copied will be available in every VM so this does not need to happen on every scale event?

To the contrary, when the AKS node pool scales out, the VMSS instances are created from the VMSS Model. This Model is defined by the Microsoft.ContainerService Resource Provider. More on VMSS model and instance view here.

When you make any changes to the node's file system, the changes shall be available only to that corresponding VMSS instance. Such manual changes are not persisted if the node undergoes a node image upgrade, Kubernetes version upgrade or reconcile operation. Also if this node gets scaled down by the AKS cluster, the changes will be lost.

Instead we recommend using DaemonSets with Read-Write hostPath volume mounts where it can add files to on the host node. Since Daemonset is a Kubernetes construct and the Daemonset controller creates one replica of the Daemonset on each node (except virtual nodes; Reference) and there shall consistently be aviable even if the node undergoes an update or reconcile operation. When the node pool is scaled up new nodes shall also get a replica of the DaemonSet each.


For Azure Virtual Machine Scale Sets in general, the easiest ways to copy files between your local machine and an Azure VMSS instance would be:

  • SCP: if the VMSS was created with --public-ip-per-vm parameter to the az vmss create command or with API version of the Microsoft.Compute/virtualMachineScaleSets resource is at least 2017-03-30, and a publicIpAddressConfiguration JSON property to the scale set ipConfigurations section is added. For example:
     "publicIpAddressConfiguration": {
         "name": "pub1",
         "properties": {
          "idleTimeoutInMinutes": 15
         }
     }
    
  • If the VMSS instances do not have a public IP of their own or are assigned public IP addresses from an Azure Load Balancer (which has the VMSS as its backend pool) then create a jumpbox VM in the same virtual network as the VMSS. You can now SCP between your local machine and the jumpbox VM using the jumpbox VM's public IP and between the jumpbox VM and the VMSS instances using private IP addresses.
Srijit_Bose-MSFT
  • 1,010
  • 4
  • 13