Skip to content
This repository has been archived by the owner on Sep 30, 2020. It is now read-only.

Commit

Permalink
feat(amazon-vpc-k8s-cni): kubelet --max-pods setting
Browse files Browse the repository at this point in the history
This prevents kubelets from trying to scheduling more pods than available IPs per node when amazon-vpc-k8s-cni is enabled
  • Loading branch information
mumoshu committed Sep 30, 2018
1 parent 9dd1b58 commit 9902c92
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 13 deletions.
43 changes: 43 additions & 0 deletions core/controlplane/config/amazon_vpc.go
Original file line number Diff line number Diff line change
@@ -1 +1,44 @@
package config

import (
"fmt"
"github.com/aws/amazon-vpc-cni-k8s/pkg/awsutils"
"github.com/kubernetes-incubator/kube-aws/node"
)

type AmazonVPC struct {
Enabled bool `yaml:"enabled"`
}

func (a AmazonVPC) MaxPodsScript() node.UploadedFileContent {
script := `#!/usr/bin/env bash
set -e
# According to https://github.com/aws/amazon-vpc-cni-k8s#eni-allocation
ips_per_eni=30
declare -A instance_eni_available
`

for it, num := range awsutils.InstanceENIsAvailable {
script = script + fmt.Sprintf(`instance_eni_available["%s"]=%d
`, it, num)
}
script = script + `
instance_type=$(curl http://169.254.169.254/latest/meta-data/instance-type)
enis=${instance_eni_available["$instance_type"]}
if [ "" == "$enis" ]; then
echo "unsupported instance type: $instance_type" 1>&2
exit 1
fi
max_pods=$(( (enis * (ips_per_eni - 1)) + 2 ))
printf $max_pods
`
return node.NewUploadedFileContent([]byte(script))
}
4 changes: 0 additions & 4 deletions core/controlplane/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -794,10 +794,6 @@ type Networking struct {
SelfHosting SelfHosting `yaml:"selfHosting"`
}

type AmazonVPC struct {
Enabled bool `yaml:"enabled"`
}

type SelfHosting struct {
Type string `yaml:"type"`
Typha bool `yaml:"typha"`
Expand Down
7 changes: 7 additions & 0 deletions core/controlplane/config/templates/cloud-config-controller
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ coreos:
{{- end }}
{{- if .Kubernetes.Networking.AmazonVPC.Enabled }}
--node-ip=$$(curl http://169.254.169.254/latest/meta-data/local-ipv4) \
--max-pods=$$(/opt/bin/aws-k8s-cni-max-pods) \
{{- end }}
$KUBELET_OPTS \
"
Expand Down Expand Up @@ -4849,6 +4850,12 @@ write_files:
{{end}}

{{if .Kubernetes.Networking.AmazonVPC.Enabled }}
- path: /opt/bin/aws-k8s-cni-max-pods
owner: root:root
permissions: 0755
encoding: gzip+base64
content: {{.Kubernetes.Networking.AmazonVPC.MaxPodsScript.ToGzip.ToBase64}}

- path: /srv/kubernetes/manifests/aws-k8s-cni.yaml
content: |
---
Expand Down
18 changes: 9 additions & 9 deletions node/uploaded_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,36 @@ import (

type UploadedFile struct {
Path string
Content uploadedFileContent
Content UploadedFileContent
}

type uploadedFileContent struct {
type UploadedFileContent struct {
bytes []byte
}

func NewUploadedFileContent(bytes []byte) uploadedFileContent {
return uploadedFileContent{
func NewUploadedFileContent(bytes []byte) UploadedFileContent {
return UploadedFileContent{
bytes: bytes,
}
}

func (c uploadedFileContent) ToBase64() uploadedFileContent {
func (c UploadedFileContent) ToBase64() UploadedFileContent {
bytes := []byte(base64.StdEncoding.EncodeToString(c.bytes))
return uploadedFileContent{
return UploadedFileContent{
bytes: bytes,
}
}

func (c uploadedFileContent) ToGzip() uploadedFileContent {
func (c UploadedFileContent) ToGzip() UploadedFileContent {
bytes, err := gzipcompressor.BytesToBytes(c.bytes)
if err != nil {
panic(fmt.Errorf("Unexpected error in ToGzip: %v", err))
}
return uploadedFileContent{
return UploadedFileContent{
bytes: bytes,
}
}

func (c uploadedFileContent) String() string {
func (c UploadedFileContent) String() string {
return string(c.bytes)
}

0 comments on commit 9902c92

Please sign in to comment.