Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Commit

Permalink
Add resource requests and limits
Browse files Browse the repository at this point in the history
  • Loading branch information
ritazh committed Jul 19, 2018
1 parent 3f7b09b commit 44f3870
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 9 deletions.
30 changes: 27 additions & 3 deletions examples/addons/keyvault-flexvolume/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,37 @@ You should see the keyvault flexvolume installer pods running on each agent node
```bash
kubectl get pods -n kv

kv-flexvol-installer-f7bx8 1/1 Running 0 3m
kv-flexvol-installer-rcxbl 1/1 Running 0 3m
kv-flexvol-installer-z6jm6 1/1 Running 0 3m
keyvault-flexvolume-f7bx8 1/1 Running 0 3m
keyvault-flexvolume-rcxbl 1/1 Running 0 3m
keyvault-flexvolume-z6jm6 1/1 Running 0 3m
```

Follow the README at https://github.com/Azure/kubernetes-keyvault-flexvol for get started steps.

##
To update resources:

```json
"kubernetesConfig": {
"addons": [
{
"name": "keyvault-flexvolume",
"enabled": true,
"containers": [
{
"name": "keyvault-flexvolume",
"image": "ritazh/kv-flexvol-installer:v0.0.3",
"cpuRequests": "100m",
"memoryRequests": "300Mi",
"cpuLimits": "100m",
"memoryLimits": "300Mi"
}
]
}
]
}
```

## Supported Orchestrators

Kubernetes
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,31 @@ apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
labels:
app: kv-flexvol-installer
app: keyvault-flexvolume
kubernetes.io/cluster-service: "true"
addonmanager.kubernetes.io/mode: "EnsureExists"
name: kv-flexvol-installer
name: keyvault-flexvolume
namespace: kv
spec:
template:
metadata:
labels:
app: kv-flexvol-installer
app: keyvault-flexvolume
kubernetes.io/cluster-service: "true"
addonmanager.kubernetes.io/mode: "EnsureExists"
spec:
tolerations:
containers:
- name: flexvol-driver-installer
- name: keyvault-flexvolume
image: "ritazh/kv-flexvol-installer:v0.0.3"
imagePullPolicy: Always
resources:
requests:
cpu: <kubernetesKeyVaultFlexVolumeInstallerCPURequests>
memory: <kubernetesKeyVaultFlexVolumeInstallerMemoryRequests>
limits:
cpu: <kubernetesKeyVaultFlexVolumeInstallerCPULimit>
memory: <kubernetesKeyVaultFlexVolumeInstallerMemoryLimit>
env:
- name: TARGET_DIR
value: "/etc/kubernetes/volumeplugins"
Expand Down
8 changes: 8 additions & 0 deletions parts/k8s/kubernetesmastercustomdata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,14 @@ MASTER_ARTIFACTS_CONFIG_PLACEHOLDER
sed -i "s|<kubernetesClusterAutoscalerUseManagedIdentity>|{{WrapAsVariable "kubernetesClusterAutoscalerUseManagedIdentity"}}|g" "/etc/kubernetes/addons/cluster-autoscaler-deployment.yaml"
{{end}}

{{if .OrchestratorProfile.KubernetesConfig.IsKeyVaultFlexVolumeEnabled}}
sed -i "s|<kubernetesKeyVaultFlexVolumeInstallerCPURequests>|{{WrapAsVariable "kubernetesKeyVaultFlexVolumeInstallerCPURequests"}}|g" "/etc/kubernetes/addons/keyvault-flexvolume-installer.yaml"
sed -i "s|<kubernetesKeyVaultFlexVolumeInstallerMemoryRequests>|{{WrapAsVariable "kubernetesKeyVaultFlexVolumeInstallerMemoryRequests"}}|g" "/etc/kubernetes/addons/keyvault-flexvolume-installer.yaml"
sed -i "s|<kubernetesKeyVaultFlexVolumeInstallerCPULimit>|{{WrapAsVariable "kubernetesKeyVaultFlexVolumeInstallerCPULimit"}}|g" "/etc/kubernetes/addons/keyvault-flexvolume-installer.yaml"
sed -i "s|<kubernetesKeyVaultFlexVolumeInstallerMemoryLimit>|{{WrapAsVariable "kubernetesKeyVaultFlexVolumeInstallerMemoryLimit"}}|g" "/etc/kubernetes/addons/keyvault-flexvolume-installer.yaml"


{{end}}
{{if .OrchestratorProfile.KubernetesConfig.IsReschedulerEnabled}}
sed -i "s|<kubernetesReschedulerSpec>|{{WrapAsVariable "kubernetesReschedulerSpec"}}|g" "/etc/kubernetes/addons/kube-rescheduler-deployment.yaml"
sed -i "s|<kubernetesReschedulerCPURequests>|{{WrapAsVariable "kubernetesReschedulerCPURequests"}}|g" "/etc/kubernetes/addons/kube-rescheduler-deployment.yaml"
Expand Down
4 changes: 4 additions & 0 deletions parts/k8s/kubernetesmastervars.t
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@
"kubernetesClusterAutoscalerMaxNodes": "[parameters('kubernetesClusterAutoscalerMaxNodes')]",
"kubernetesClusterAutoscalerEnabled": "[parameters('kubernetesClusterAutoscalerEnabled')]",
"kubernetesClusterAutoscalerUseManagedIdentity": "[parameters('kubernetesClusterAutoscalerUseManagedIdentity')]",
"kubernetesKeyVaultFlexVolumeInstallerCPURequests": "[parameters('kubernetesKeyVaultFlexVolumeInstallerCPURequests')]",
"kubernetesKeyVaultFlexVolumeInstallerMemoryRequests": "[parameters('kubernetesKeyVaultFlexVolumeInstallerMemoryRequests')]",
"kubernetesKeyVaultFlexVolumeInstallerCPULimit": "[parameters('kubernetesKeyVaultFlexVolumeInstallerCPULimit')]",
"kubernetesKeyVaultFlexVolumeInstallerMemoryLimit": "[parameters('kubernetesKeyVaultFlexVolumeInstallerMemoryLimit')]",
"kubernetesReschedulerSpec": "[parameters('kubernetesReschedulerSpec')]",
"kubernetesReschedulerCPURequests": "[parameters('kubernetesReschedulerCPURequests')]",
"kubernetesReschedulerMemoryRequests": "[parameters('kubernetesReschedulerMemoryRequests')]",
Expand Down
28 changes: 28 additions & 0 deletions parts/k8s/kubernetesparams.t
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,34 @@
},
"type": "string"
},
"kubernetesKeyVaultFlexVolumeInstallerCPURequests": {
{{PopulateClassicModeDefaultValue "kubernetesKeyVaultFlexVolumeInstallerCPURequests"}}
"metadata": {
"description": "Key Vault FlexVolume Installer CPU Requests"
},
"type": "string"
},
"kubernetesKeyVaultFlexVolumeInstallerMemoryRequests": {
{{PopulateClassicModeDefaultValue "kubernetesKeyVaultFlexVolumeInstallerMemoryRequests"}}
"metadata": {
"description": "Key Vault FlexVolume Installer Memory Requests"
},
"type": "string"
},
"kubernetesKeyVaultFlexVolumeInstallerCPULimit": {
{{PopulateClassicModeDefaultValue "kubernetesKeyVaultFlexVolumeInstallerCPULimit"}}
"metadata": {
"description": "Key Vault FlexVolume Installer CPU Limit"
},
"type": "string"
},
"kubernetesKeyVaultFlexVolumeInstallerMemoryLimit": {
{{PopulateClassicModeDefaultValue "kubernetesKeyVaultFlexVolumeInstallerMemoryLimit"}}
"metadata": {
"description": "Key Vault FlexVolume Installer Memory Limit"
},
"type": "string"
},
"kubernetesReschedulerSpec": {
{{PopulateClassicModeDefaultValue "kubernetesReschedulerSpec"}}
"metadata": {
Expand Down
9 changes: 9 additions & 0 deletions pkg/acsengine/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,15 @@ var (
DefaultKeyVaultFlexVolumeAddonsConfig = api.KubernetesAddon{
Name: DefaultKeyVaultFlexVolumeAddonName,
Enabled: helpers.PointerToBool(api.DefaultKeyVaultFlexVolumeAddonEnabled),
Containers: []api.KubernetesContainerSpec{
{
Name: DefaultKeyVaultFlexVolumeAddonName,
CPURequests: "50m",
MemoryRequests: "10Mi",
CPULimits: "50m",
MemoryLimits: "10Mi",
},
},
}

// DefaultDashboardAddonsConfig is the default kubernetes-dashboard addon Config
Expand Down
8 changes: 8 additions & 0 deletions pkg/acsengine/params_k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ func assignKubernetesParameters(properties *api.Properties, parametersMap params
addValue(parametersMap, "kubernetesClusterAutoscalerSpec", cloudSpecConfig.KubernetesSpecConfig.KubernetesImageBase+KubeConfigs[k8sVersion][DefaultClusterAutoscalerAddonName])
}
}
kvFlexVolumeInstallerAddon := getAddonByName(properties.OrchestratorProfile.KubernetesConfig.Addons, DefaultKeyVaultFlexVolumeAddonName)
c = getAddonContainersIndexByName(kvFlexVolumeInstallerAddon.Containers, DefaultKeyVaultFlexVolumeAddonName)
if c > -1 {
addValue(parametersMap, "kubernetesKeyVaultFlexVolumeInstallerCPURequests", kvFlexVolumeInstallerAddon.Containers[c].CPURequests)
addValue(parametersMap, "kubernetesKeyVaultFlexVolumeInstallerCPULimit", kvFlexVolumeInstallerAddon.Containers[c].CPULimits)
addValue(parametersMap, "kubernetesKeyVaultFlexVolumeInstallerMemoryRequests", kvFlexVolumeInstallerAddon.Containers[c].MemoryRequests)
addValue(parametersMap, "kubernetesKeyVaultFlexVolumeInstallerMemoryLimit", kvFlexVolumeInstallerAddon.Containers[c].MemoryLimits)
}
dashboardAddon := getAddonByName(properties.OrchestratorProfile.KubernetesConfig.Addons, DefaultDashboardAddonName)
c = getAddonContainersIndexByName(dashboardAddon.Containers, DefaultDashboardAddonName)
if c > -1 {
Expand Down
26 changes: 26 additions & 0 deletions pkg/acsengine/template_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,8 @@ func (t *TemplateGenerator) getTemplateFuncMap(cs *api.ContainerService) templat
mC := getAddonContainersIndexByName(metricsServerAddon.Containers, DefaultMetricsServerAddonName)
nvidiaDevicePluginAddon := getAddonByName(cs.Properties.OrchestratorProfile.KubernetesConfig.Addons, NVIDIADevicePluginAddonName)
nC := getAddonContainersIndexByName(nvidiaDevicePluginAddon.Containers, NVIDIADevicePluginAddonName)
kvFlexVolumeAddon := getAddonByName(cs.Properties.OrchestratorProfile.KubernetesConfig.Addons, DefaultKeyVaultFlexVolumeAddonName)
kC := getAddonContainersIndexByName(kvFlexVolumeAddon.Containers, DefaultKeyVaultFlexVolumeAddonName)
switch attr {
case "kubernetesHyperkubeSpec":
val = cs.Properties.OrchestratorProfile.KubernetesConfig.KubernetesImageBase + KubeConfigs[k8sVersion]["hyperkube"]
Expand Down Expand Up @@ -917,6 +919,30 @@ func (t *TemplateGenerator) getTemplateFuncMap(cs *api.ContainerService) templat
val = "false"
}
}
case "kubernetesKeyVaultFlexVolumeInstallerCPURequests":
if kC > -1 {
val = kvFlexVolumeAddon.Containers[kC].CPURequests
} else {
val = ""
}
case "kubernetesKeyVaultFlexVolumeInstallerMemoryRequests":
if kC > -1 {
val = kvFlexVolumeAddon.Containers[kC].MemoryRequests
} else {
val = ""
}
case "kubernetesKeyVaultFlexVolumeInstallerCPULimit":
if kC > -1 {
val = kvFlexVolumeAddon.Containers[kC].CPULimits
} else {
val = ""
}
case "kubernetesKeyVaultFlexVolumeInstallerMemoryLimit":
if kC > -1 {
val = kvFlexVolumeAddon.Containers[kC].MemoryLimits
} else {
val = ""
}
case "kubernetesTillerSpec":
if tC > -1 {
if tillerAddon.Containers[tC].Image != "" {
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/kubernetes/kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,11 +352,11 @@ var _ = Describe("Azure Container Cluster using the Kubernetes Orchestrator", fu

It("should have keyvault-flexvolume running", func() {
if hasKeyVaultFlexVolume, KeyVaultFlexVolumeAddon := eng.HasAddon("keyvault-flexvolume"); hasKeyVaultFlexVolume {
running, err := pod.WaitOnReady("kv-flexvol-installer-", "kv", 3, 30*time.Second, cfg.Timeout)
running, err := pod.WaitOnReady("keyvault-flexvolume-", "kv", 3, 30*time.Second, cfg.Timeout)
Expect(err).NotTo(HaveOccurred())
Expect(running).To(Equal(true))
By("Ensuring that the correct resources have been applied")
pods, err := pod.GetAllByPrefix("kv-flexvol-installer-", "kv")
pods, err := pod.GetAllByPrefix("keyvault-flexvolume-", "kv")
Expect(err).NotTo(HaveOccurred())
for i, c := range KeyVaultFlexVolumeAddon.Containers {
err := pods[0].Spec.Containers[i].ValidateResources(c)
Expand Down

0 comments on commit 44f3870

Please sign in to comment.