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

Commit

Permalink
hardcoded kubelet config.yaml generation
Browse files Browse the repository at this point in the history
  • Loading branch information
preved911 committed Feb 24, 2020
1 parent aced211 commit 9a5dc73
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
k8s.io/apimachinery v0.17.2
k8s.io/client-go v0.17.2
k8s.io/klog v1.0.0
k8s.io/kubelet v0.0.0
k8s.io/kubernetes v1.17.2
)

Expand Down
43 changes: 42 additions & 1 deletion kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ import (
restclient "k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"

kubeletphase "k8s.io/kubernetes/cmd/kubeadm/app/phases/kubelet"
// kubeletconfig "k8s.io/kubernetes/pkg/kubelet/apis/config"
kubeletconfig "k8s.io/kubelet/config/v1beta1"
)

// func parseCertCA(certificatesDir string) ([]byte, error) {
Expand Down Expand Up @@ -112,7 +116,7 @@ func kubeletCertKeyGen(nodeName, certificatesDir string) ([]byte, []byte, error)
return publicKey, privateKeyData, nil
}

func kubeletConfigCreate(nodeName, certificatesDir string) error {
func kubeletKubeConfigCreate(nodeName, certificatesDir string) error {
var kubeletConfigFile string = fmt.Sprintf("kubelet-%s.conf", nodeName)

// check kubelet.conf existence
Expand Down Expand Up @@ -169,3 +173,40 @@ func kubeletConfigCreate(nodeName, certificatesDir string) error {
filepath.Join(certificatesDir, kubeletConfigFile),
)
}

func kubeletConfigCreate(certificatesDir string) error {
var (
healthzPort int32 = 10248
kubeletAnonymousAuthenticationEnabled, kubeletWebhookAuthenticationEnabled bool
)

kubeletWebhookAuthenticationEnabled = true

kubeletConfig := &kubeletconfig.KubeletConfiguration{
Authentication: kubeletconfig.KubeletAuthentication{
X509: kubeletconfig.KubeletX509Authentication{
ClientCAFile: "/etc/kubernetes/pki/ca.crt",
},
Webhook: kubeletconfig.KubeletWebhookAuthentication{
Enabled: &kubeletWebhookAuthenticationEnabled,
},
Anonymous: kubeletconfig.KubeletAnonymousAuthentication{
Enabled: &kubeletAnonymousAuthenticationEnabled,
},
},
Authorization: kubeletconfig.KubeletAuthorization{
Mode: "Webhook",
},
CgroupDriver: "systemd",
ClusterDNS: []string{"10.96.0.10"},
ClusterDomain: "cluster.local",
HealthzBindAddress: "127.0.0.1",
HealthzPort: &healthzPort,
RotateCertificates: true,
StaticPodPath: "/etc/kubernetes/manifests",
}

return kubeletphase.WriteConfigToDisk(
kubeletConfig,
certificatesDir)
}
6 changes: 5 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@ func main() {
}

for _, nodeName := range cfg.Nodes {
if err := kubeletConfigCreate(nodeName, cfg.initConfiguration.CertificatesDir); err != nil {
if err := kubeletKubeConfigCreate(nodeName, cfg.initConfiguration.CertificatesDir); err != nil {
log.Fatalln(err)
}
}

if err := kubeletConfigCreate(cfg.initConfiguration.CertificatesDir); err != nil {
log.Fatalln(err)
}
}

0 comments on commit 9a5dc73

Please sign in to comment.