From 6f748f4375318000bc013207bf059e45e7c63108 Mon Sep 17 00:00:00 2001 From: Bhargav Nookala Date: Fri, 23 Feb 2018 14:06:23 -0800 Subject: [PATCH] Adding support for ACI DNS name labels (#97) --- README.md | 5 +++ providers/azure/README.md | 51 ++++++++++++++++++++++++++-- providers/azure/aci.go | 6 ++++ providers/azure/client/aci/client.go | 4 +-- providers/azure/client/aci/types.go | 7 ++-- 5 files changed, 65 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 4b77b5d2c..bd75f260f 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,7 @@ a `virtual-kubelet` node. * Environment variables * Public IPs * kubectl logs +* DNS name labels ## Current Limitations @@ -116,6 +117,10 @@ You can find detailed instructions on how to set it up and how to test it in the The Azure connector can use a configuration file specified by the `--provider-config` flag. The config file is in TOML format, and an example lives in `providers/azure/example.toml`. +#### More Details + +See the [ACI Readme](providers/azure/README.md) + ### Hyper.sh Provider The Hyper.sh Provider allows Kubernetes clusters to deploy Hyper.sh containers diff --git a/providers/azure/README.md b/providers/azure/README.md index ffc2a4d6b..b3e4142a8 100644 --- a/providers/azure/README.md +++ b/providers/azure/README.md @@ -284,15 +284,60 @@ Name ResourceGroup ProvisioningState Image helloworld-2559879000-8vmjw myResourceGroup Succeeded microsoft/aci-helloworld 52.179.3.180:80 1.0 core/1.5 gb Linux eastus ``` +### Schedule an ACI pod with a DNS Name label + +Add an annotation to your Pod manifest, `virtualkubelet.io/dnsnamelabel` keyed to what you'd like the Azure Container Instance to receive as a DNS Name, and deploy it. + +```yaml +apiVersion: v1 +kind: Pod +metadata: + name: helloworld + annotations: + virtualkubelet.io/dnsnamelabel: "helloworld-aci" +spec: + containers: + - image: microsoft/aci-helloworld + imagePullPolicy: Always + name: helloworld + resources: + requests: + memory: 1G + cpu: 1 + ports: + - containerPort: 80 + name: http + protocol: TCP + - containerPort: 443 + name: https + dnsPolicy: ClusterFirst + nodeName: virtual-kubelet +``` + +To confirm the Azure Container Instance received and bound the DNS Name specified, use the [az container show][az-container-show] Azure CLI command. Virtual Kubelet's naming +convention will affect how you use this query, with the argument to `-n` broken down as: nameSpace-podName. Unless specified, Kubernetes will assume +the namespace is `default`. + +```azurecli-interactive +az container show -g myResourceGroup -n default-helloworld --query ipAddress.fqdn +``` + +Output: + +```console +"helloworld-aci.westus.azurecontainer.io" +``` + ## Remove the Virtual Kubelet -You can remove your Virtual Kubelet node, you can delete the Helm deployment, by running the following command: +You can remove your Virtual Kubelet node by deleting the Helm deployment. Run the following command: ``` helm delete virtual-kubelet --purge -``` +``` [kubectl-create]: https://kubernetes.io/docs/user-guide/kubectl/v1.6/#create [kubectl-get]: https://kubernetes.io/docs/user-guide/kubectl/v1.8/#get -[az-container-list]: https://docs.microsoft.com/en-us/cli/azure/aks?view=azure-cli-latest#az_aks_list +[az-container-list]: https://docs.microsoft.com/en-us/cli/azure/container?view=azure-cli-latest#az_container_list +[az-container-show]: https://docs.microsoft.com/en-us/cli/azure/container?view=azure-cli-latest#az_container_show diff --git a/providers/azure/aci.go b/providers/azure/aci.go index db1766984..d2f1bad83 100644 --- a/providers/azure/aci.go +++ b/providers/azure/aci.go @@ -26,6 +26,8 @@ import ( // The service account secret mount path. const serviceAccountSecretMountPath = "/var/run/secrets/kubernetes.io/serviceaccount" +const virtualKubeletDNSNameLabel = "virtualkubelet.io/dnsnamelabel" + // ACIProvider implements the virtual-kubelet provider interface and communicates with Azure's ACI APIs. type ACIProvider struct { aciClient *aci.Client @@ -231,6 +233,10 @@ func (p *ACIProvider) CreatePod(pod *v1.Pod) error { Ports: ports, Type: "Public", } + + if dnsNameLabel := pod.Annotations[virtualKubeletDNSNameLabel]; dnsNameLabel != "" { + containerGroup.ContainerGroupProperties.IPAddress.DNSNameLabel = dnsNameLabel + } } podUID := string(pod.UID) diff --git a/providers/azure/client/aci/client.go b/providers/azure/client/aci/client.go index e760ed30a..9b9efb3ee 100644 --- a/providers/azure/client/aci/client.go +++ b/providers/azure/client/aci/client.go @@ -10,8 +10,8 @@ import ( const ( // BaseURI is the default URI used for compute services. BaseURI = "https://management.azure.com" - userAgent = "virtual-kubelet/azure-arm-aci/2017-12-01" - apiVersion = "2017-12-01-preview" + userAgent = "virtual-kubelet/azure-arm-aci/2018-02-01" + apiVersion = "2018-02-01-preview" containerGroupURLPath = "subscriptions/{{.subscriptionId}}/resourceGroups/{{.resourceGroup}}/providers/Microsoft.ContainerInstance/containerGroups/{{.containerGroupName}}" containerGroupListURLPath = "subscriptions/{{.subscriptionId}}/providers/Microsoft.ContainerInstance/containerGroups" diff --git a/providers/azure/client/aci/types.go b/providers/azure/client/aci/types.go index 82b18a233..9f7793431 100644 --- a/providers/azure/client/aci/types.go +++ b/providers/azure/client/aci/types.go @@ -172,9 +172,10 @@ type ImageRegistryCredential struct { // IPAddress is IP address for the container group. type IPAddress struct { - Ports []Port `json:"ports,omitempty"` - Type string `json:"type,omitempty"` - IP string `json:"ip,omitempty"` + Ports []Port `json:"ports,omitempty"` + Type string `json:"type,omitempty"` + IP string `json:"ip,omitempty"` + DNSNameLabel string `json:"dnsNameLabel,omitempty"` } // Logs is the logs.