Skip to content
This repository was archived by the owner on Nov 1, 2023. It is now read-only.

Commit 3de04b3

Browse files
authored
Merge pull request #41 from stephenmoloney/feature/use-kubeadm-yaml-2
Introduce yaml files as config for kubeadm for v1.12+
2 parents 475a99a + a3de9d7 commit 3de04b3

File tree

5 files changed

+132
-18
lines changed

5 files changed

+132
-18
lines changed

kubeadm/v1alpha3-config.yaml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
apiVersion: kubeadm.k8s.io/v1alpha3
3+
kind: InitConfiguration
4+
apiEndpoint:
5+
advertiseAddress: CONFIG_CLUSTER_PRIVATE_IP
6+
bindPort: 6443
7+
nodeRegistration:
8+
kubeletExtraArgs:
9+
"feature-gates": "BlockVolume=true,CRIContainerLogRotation=true"
10+
11+
12+
---
13+
apiVersion: kubeadm.k8s.io/v1alpha3
14+
kind: ClusterConfiguration
15+
kubernetesVersion: CONFIG_KUBERNETES_VERSION
16+
apiServerCertSANs:
17+
- CONFIG_CLUSTER_PUBLIC_IP
18+
apiServerExtraArgs:
19+
authorization-mode: Node,RBAC
20+
certificatesDir: /etc/kubernetes/pki
21+
clusterName: kubernetes
22+
imageRepository: k8s.gcr.io
23+
24+
25+
---
26+
apiVersion: kubelet.config.k8s.io/v1beta1
27+
kind: KubeletConfiguration
28+
containerLogMaxFiles: 1
29+
containerLogMaxSize: CONFIG_CONTAINER_LOG_MAX_SIZE
30+
maxPods: 110
31+
featureGates:
32+
BlockVolume: true
33+
CRIContainerLogRotation: true
34+
35+
---
36+
apiVersion: kubeproxy.config.k8s.io/v1alpha1
37+
kind: KubeProxyConfiguration
38+
39+
40+
# ---
41+
# apiVersion: kubeadm.k8s.io/v1alpha3
42+
# kind: JoinConfiguration
43+

kubeadm/v1beta1-config.yaml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
apiVersion: kubeadm.k8s.io/v1beta1
3+
kind: InitConfiguration
4+
localAPIEndpoint:
5+
advertiseAddress: CONFIG_CLUSTER_PRIVATE_IP
6+
bindPort: 6443
7+
nodeRegistration:
8+
kubeletExtraArgs:
9+
"feature-gates": "BlockVolume=true,CRIContainerLogRotation=true"
10+
11+
12+
---
13+
apiVersion: kubeadm.k8s.io/v1beta1
14+
kind: ClusterConfiguration
15+
kubernetesVersion: CONFIG_KUBERNETES_VERSION
16+
apiServer:
17+
extraArgs:
18+
authorization-mode: Node,RBAC
19+
certSANs:
20+
- CONFIG_CLUSTER_PUBLIC_IP
21+
timeoutForControlPlane: 4m0s
22+
controlPlaneEndpoint: CONFIG_CLUSTER_PRIVATE_IP:6443
23+
controllerManager:
24+
extraArgs:
25+
"node-cidr-mask-size": "20"
26+
scheduler:
27+
extraArgs:
28+
address: CONFIG_CLUSTER_PRIVATE_IP
29+
certificatesDir: /etc/kubernetes/pki
30+
imageRepository: k8s.gcr.io
31+
useHyperKubeImage: false
32+
33+
34+
---
35+
apiVersion: kubelet.config.k8s.io/v1beta1
36+
kind: KubeletConfiguration
37+
containerLogMaxFiles: 1
38+
containerLogMaxSize: CONFIG_CONTAINER_LOG_MAX_SIZE
39+
maxPods: 110
40+
featureGates:
41+
BlockVolume: true
42+
CRIContainerLogRotation: true
43+
44+
45+
---
46+
apiVersion: kubeproxy.config.k8s.io/v1alpha1
47+
kind: KubeProxyConfiguration
48+
49+
50+
# ---
51+
# apiVersion: kubeadm.k8s.io/v1beta1
52+
# kind: JoinConfiguration

master.tf

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@ resource "scaleway_server" "k8s_master" {
1010
public_ip = "${element(scaleway_ip.k8s_master_ip.*.ip, count.index)}"
1111
security_group = "${scaleway_security_group.master_security_group.id}"
1212

13-
// volume {
14-
// size_in_gb = 50
15-
// type = "l_ssd"
16-
// }
17-
1813
connection {
1914
type = "ssh"
2015
user = "root"
@@ -28,13 +23,18 @@ resource "scaleway_server" "k8s_master" {
2823
source = "addons/"
2924
destination = "/tmp"
3025
}
26+
provisioner "file" {
27+
source = "kubeadm"
28+
destination = "/tmp/"
29+
}
3130
provisioner "remote-exec" {
3231
inline = [
3332
<<EOT
3433
#!/bin/bash
3534
set -e
3635
chmod +x /tmp/docker-install.sh
3736
chmod +x /tmp/kubeadm-install.sh
37+
chmod g+w -R /tmp/kubeadm/
3838
3939
export ubuntu_version=$(echo -n ${var.ubuntu_version} | cut -d " " -f 2 | awk '{print tolower($0)}')
4040
/tmp/docker-install.sh $${ubuntu_version} ${var.arch} ${var.docker_version} && \
@@ -53,18 +53,37 @@ modify_kube_apiserver_config(){
5353
if [[ ${var.arch} == "arm" ]]; then modify_kube_apiserver_config & fi
5454
5555
export KUBEADM_VERSION=$(apt-cache madison kubeadm | grep $(echo ${var.k8s_version} | cut -c8-) | \
56-
head -1 | awk '{print $3}' | rev | cut -c4- | rev)
56+
awk 'NR==1 {print $3}' | rev | cut -c4- | rev)
57+
58+
dpkg --compare-versions "$${KUBEADM_VERSION}" lt 1.13 && \
59+
export KUBEADM_CONFIG_FILE=/tmp/kubeadm/v1alpha3-config.yaml || \
60+
export KUBEADM_CONFIG_FILE=/tmp/kubeadm/v1beta1-config.yaml
61+
62+
dpkg --compare-versions "$${KUBEADM_VERSION}" lt 1.12 && \
63+
export KUBEADM_CONFIG_FILE=""
5764
5865
dpkg --compare-versions "$${KUBEADM_VERSION}" lt 1.11 && \
5966
export VERBOSITY_EXTRA_ARGS='' || \
6067
export VERBOSITY_EXTRA_ARGS='--v ${var.kubeadm_verbosity}'
6168
62-
kubeadm init \
63-
--apiserver-advertise-address=${self.private_ip} \
64-
--apiserver-cert-extra-sans=${self.public_ip} \
65-
--kubernetes-version=${var.k8s_version} \
66-
--ignore-preflight-errors=KubeletVersion \
67-
$${VERBOSITY_EXTRA_ARGS};
69+
if [[ -z "$${KUBEADM_CONFIG_FILE}" ]]; then
70+
kubeadm init \
71+
--apiserver-advertise-address=${self.private_ip} \
72+
--apiserver-cert-extra-sans=${self.public_ip} \
73+
--kubernetes-version=${var.k8s_version} \
74+
--ignore-preflight-errors=KubeletVersion \
75+
$${VERBOSITY_EXTRA_ARGS};
76+
else
77+
sed -i 's/CONFIG_CLUSTER_PUBLIC_IP/${self.public_ip}/g' $${KUBEADM_CONFIG_FILE} && \
78+
sed -i 's/CONFIG_CLUSTER_PRIVATE_IP/${self.private_ip}/g' $${KUBEADM_CONFIG_FILE} && \
79+
sed -i "s/CONFIG_KUBERNETES_VERSION/v$${KUBEADM_VERSION}/g" $${KUBEADM_CONFIG_FILE} && \
80+
sed -i "s/CONFIG_CONTAINER_LOG_MAX_SIZE/${var.container_log_max_size}/" $${KUBEADM_CONFIG_FILE}
81+
82+
kubeadm init \
83+
--ignore-preflight-errors=KubeletVersion \
84+
--config=$${KUBEADM_CONFIG_FILE} \
85+
$${VERBOSITY_EXTRA_ARGS};
86+
fi && \
6887
6988
mkdir -p $HOME/.kube && cp -i /etc/kubernetes/admin.conf $HOME/.kube/config && \
7089
kubectl create secret -n kube-system generic weave-passwd --from-literal=weave-passwd=${var.weave_passwd} && \

nodes.tf

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@ resource "scaleway_server" "k8s_node" {
1010
public_ip = "${element(scaleway_ip.k8s_node_ip.*.ip, count.index)}"
1111
security_group = "${scaleway_security_group.node_security_group.id}"
1212

13-
// volume {
14-
// size_in_gb = 50
15-
// type = "l_ssd"
16-
// }
17-
1813
connection {
1914
type = "ssh"
2015
user = "root"

variables.tf

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ EOT
3434
}
3535

3636
variable "k8s_version" {
37-
default = "stable-1.12"
37+
default = "stable-1.13"
3838
}
3939

4040
variable "weave_passwd" {
@@ -77,6 +77,11 @@ variable "private_key" {
7777
description = "The path to your private key"
7878
}
7979

80+
variable "container_log_max_size" {
81+
default = "100Mi"
82+
description = "The maximum file size for container logs, k8s 1.12+ only"
83+
}
84+
8085
variable "kubeadm_verbosity" {
8186
default = "0"
8287
description = "The verbosity level of the kubeadm init logs"

0 commit comments

Comments
 (0)