Skip to content

Commit

Permalink
fix: kubelet unmarshal failed
Browse files Browse the repository at this point in the history
  • Loading branch information
Downager committed Apr 21, 2022
1 parent ce96631 commit 0cb1bd7
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 51 deletions.
2 changes: 1 addition & 1 deletion kube-apiserver.tf
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ data "ignition_file" "kube_apiserver" {
etcd_endpoints = var.etcd_endpoints
cluster_cidr = var.pod_network_cidr
service_cidr = var.service_network_cidr
resources = local.component_resources["kube-apiserver"]
resources = local.components_resource["kube_apiserver"]

// TODO: move to merged_apiserver_flags
cloud_provider = local.cloud_config.provider
Expand Down
2 changes: 1 addition & 1 deletion kube-controller-manager.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ data "ignition_file" "kube_controller_manager" {
cloud_provider = local.cloud_config.provider
cloud_config_flag = local.cloud_config.path != "" ? "- --cloud-config=${local.cloud_config.path}" : "# no cloud provider config given"
extra_flags = local.controller_manager_flags
resources = local.component_resources["kube-controller-manager"]
resources = local.components_resource["kube_controller_manager"]
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion kube-scheduler.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ data "ignition_file" "kube_scheduler" {
image = "${local.containers["kube_scheduler"].repo}:${local.containers["kube_scheduler"].tag}"
kubeconfig = "${local.etc_path}/scheduler.conf"
extra_flags = local.scheduler_flags
resources = local.component_resources["kube-scheduler"]
resources = local.components_resource["kube_scheduler"]
})
}
}
19 changes: 18 additions & 1 deletion templates/manifests/kube-apiserver.yaml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,24 @@ spec:
initialDelaySeconds: 15
timeoutSeconds: 15
resources:
${indent(6, yamlencode(resources))}
%{ if resources["cpu_request"] != "" || resources["memory_request"] != "" ~}
requests:
%{ if resources["cpu_request"] != "" ~}
cpu: ${resources["cpu_request"]}
%{ endif ~}
%{ if resources["memory_request"] != "" ~}
memory: ${resources["memory_request"]}
%{ endif ~}
%{ endif ~}
%{ if resources["cpu_limit"] != "" || resources["memory_limit"] != "" ~}
limits:
%{ if resources["cpu_limit"] != "" ~}
cpu: ${resources["cpu_limit"]}
%{ endif ~}
%{ if resources["memory_limit"] != "" ~}
memory: ${resources["memory_limit"]}
%{ endif ~}
%{ endif ~}
volumeMounts:
- mountPath: /etc/ssl/certs
name: ca-certs
Expand Down
19 changes: 18 additions & 1 deletion templates/manifests/kube-controller-manager.yaml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,24 @@ spec:
initialDelaySeconds: 15
timeoutSeconds: 15
resources:
${indent(6, yamlencode(resources))}
%{ if resources["cpu_request"] != "" || resources["memory_request"] != "" ~}
requests:
%{ if resources["cpu_request"] != "" ~}
cpu: ${resources["cpu_request"]}
%{ endif ~}
%{ if resources["memory_request"] != "" ~}
memory: ${resources["memory_request"]}
%{ endif ~}
%{ endif ~}
%{ if resources["cpu_limit"] != "" || resources["memory_limit"] != "" ~}
limits:
%{ if resources["cpu_limit"] != "" ~}
cpu: ${resources["cpu_limit"]}
%{ endif ~}
%{ if resources["memory_limit"] != "" ~}
memory: ${resources["memory_limit"]}
%{ endif ~}
%{ endif ~}
volumeMounts:
- mountPath: /etc/ssl/certs
name: ca-certs
Expand Down
19 changes: 18 additions & 1 deletion templates/manifests/kube-scheduler.yaml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,24 @@ spec:
initialDelaySeconds: 15
timeoutSeconds: 15
resources:
${indent(6, yamlencode(resources))}
%{ if resources["cpu_request"] != "" || resources["memory_request"] != "" ~}
requests:
%{ if resources["cpu_request"] != "" ~}
cpu: ${resources["cpu_request"]}
%{ endif ~}
%{ if resources["memory_request"] != "" ~}
memory: ${resources["memory_request"]}
%{ endif ~}
%{ endif ~}
%{ if resources["cpu_limit"] != "" || resources["memory_limit"] != "" ~}
limits:
%{ if resources["cpu_limit"] != "" ~}
cpu: ${resources["cpu_limit"]}
%{ endif ~}
%{ if resources["memory_limit"] != "" ~}
memory: ${resources["memory_limit"]}
%{ endif ~}
%{ endif ~}
volumeMounts:
- mountPath: ${kubeconfig}
name: kubeconfig
Expand Down
27 changes: 11 additions & 16 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ variable "containers" {
default = {}
}

variable "components_resource" {
description = "Desired resource requests and limits of kubernetes components(kube-apiserver, kube-controller-manager, kube-scheduler, etc.)"
type = map(object({
cpu_request = string
cpu_limit = string
memory_request = string
memory_limit = string
}))
default = {}
}

variable "internal_endpoint" {
description = "The internal endpoint of kube-apiserver."
type = string
Expand Down Expand Up @@ -139,22 +150,6 @@ variable "scheduler_flags" {
default = {}
}


variable "component_resources" {
description = "Resource mangement for kube-apiserver, kube-controller-manager, kube-scheduler, etc."
type = map(object({
requests = object({
cpu = string
memory = string
})
limits = object({
cpu = string
memory = string
})
}))
default = {}
}

variable "certs" {
description = "The kubernetes and etcd certificate."
type = map(string)
Expand Down
46 changes: 17 additions & 29 deletions variables_defaults.tf
Original file line number Diff line number Diff line change
Expand Up @@ -119,36 +119,24 @@ locals {
api_audiences = ""
}, var.oidc_config)

component_resources = merge({
kube-apiserver = {
requests = {
cpu = "400m"
memory = "1536Mi"
},
limits = {
cpu = "400m"
memory = "1536Mi"
}
components_resource = merge({
kube_apiserver = {
cpu_request = "400m"
memory_request = "1536Mi"
cpu_limit = "400m"
memory_limit = "1536Mi"
},
kube-controller-manager = {
requests = {
cpu = "200m"
memory = ""
},
limits = {
cpu = ""
memory = ""
}
kube_controller_manager = {
cpu_request = "200m"
memory_request = ""
cpu_limit = ""
memory_limit = ""
},
kube-scheduler = {
requests = {
cpu = "100m"
memory = ""
},
limits = {
cpu = ""
memory = ""
}
kube_scheduler = {
cpu_request = "100m"
memory_request = ""
cpu_limit = ""
memory_limit = ""
}
}, var.component_resources)
}, var.components_resource)
}

0 comments on commit 0cb1bd7

Please sign in to comment.