Skip to content

Commit ddb9a57

Browse files
committed
CKS: Support Ciilum and new dashboard
Usage: cd scripts/util/ ./create-kubernetes-binaries-iso.sh ./ 1.34.1 1.8.0 1.34.0 \ ./cks-config-cilium.yaml \ ./cks-config-dashboard.yaml \ cks-1.34.1-cilium-1.18.1 Refer to https://docs.cloudstack.apache.org/en/latest/plugins/cloudstack-kubernetes-service.html#kubernetes-supported-versions dashboard: https://artifacthub.io/packages/helm/k8s-dashboard/kubernetes-dashboard/7.13.0 cilium: https://artifacthub.io/packages/helm/cilium/cilium/1.18.1
1 parent e78b5cc commit ddb9a57

File tree

6 files changed

+115
-8
lines changed

6 files changed

+115
-8
lines changed

plugins/integrations/kubernetes-service/src/main/resources/conf/k8s-control-node-add.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ write_files:
111111
echo "Installing binaries from ${BINARIES_DIR}"
112112
mkdir -p /opt/cni/bin
113113
tar -f "${BINARIES_DIR}/cni/cni-plugins-"*64.tgz -C /opt/cni/bin -xz
114+
chown -R root:root /opt/cni/bin/
114115
115116
mkdir -p /opt/bin
116117
tar -f "${BINARIES_DIR}/cri-tools/crictl-linux-"*64.tar.gz -C /opt/bin -xz
@@ -178,6 +179,7 @@ write_files:
178179
echo "Warning: ${BINARIES_DIR} not found. Will get binaries and docker images from Internet."
179180
mkdir -p /opt/cni/bin
180181
curl -L "https://github.com/containernetworking/plugins/releases/download/${CNI_VERSION}/cni-plugins-amd64-${CNI_VERSION}.tgz" | tar -C /opt/cni/bin -xz
182+
chown -R root:root /opt/cni/bin/
181183
182184
mkdir -p /opt/bin
183185
curl -L "https://github.com/kubernetes-incubator/cri-tools/releases/download/${CRICTL_VERSION}/crictl-${CRICTL_VERSION}-linux-amd64.tar.gz" | tar -C /opt/bin -xz
@@ -278,6 +280,13 @@ write_files:
278280
ExecStartPre=/usr/bin/curl -k https://{{ k8s_control_node.join_ip }}:6443/version
279281
ExecStart=/opt/bin/deploy-kube-system
280282
283+
- path: /etc/crictl.yaml
284+
permissions: '0700'
285+
owner: root:root
286+
content: |
287+
runtime-endpoint: unix:///var/run/containerd/containerd.sock
288+
image-endpoint: unix:///var/run/containerd/containerd.sock
289+
281290
runcmd:
282291
- chown -R cloud:cloud /home/cloud/.ssh
283292
- containerd config default > /etc/containerd/config.toml

plugins/integrations/kubernetes-service/src/main/resources/conf/k8s-control-node.yml

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ write_files:
132132
echo "Installing binaries from ${BINARIES_DIR}"
133133
mkdir -p /opt/cni/bin
134134
tar -f "${BINARIES_DIR}/cni/cni-plugins-"*64.tgz -C /opt/cni/bin -xz
135+
chown -R root:root /opt/cni/bin/
135136
136137
mkdir -p /opt/bin
137138
tar -f "${BINARIES_DIR}/cri-tools/crictl-linux-"*64.tar.gz -C /opt/bin -xz
@@ -201,6 +202,7 @@ write_files:
201202
echo "Warning: ${BINARIES_DIR} not found. Will get binaries and docker images from Internet."
202203
mkdir -p /opt/cni/bin
203204
curl -L "https://github.com/containernetworking/plugins/releases/download/${CNI_VERSION}/cni-plugins-amd64-${CNI_VERSION}.tgz" | tar -C /opt/cni/bin -xz
205+
chown -R root:root /opt/cni/bin/
204206
205207
mkdir -p /opt/bin
206208
curl -L "https://github.com/kubernetes-incubator/cri-tools/releases/download/${CRICTL_VERSION}/crictl-${CRICTL_VERSION}-linux-amd64.tar.gz" | tar -C /opt/bin -xz
@@ -264,6 +266,51 @@ write_files:
264266
bindPort: {{ k8s.api_server_port }}
265267
certificateKey: {{ k8s_control.certificate_key }}
266268
269+
- path: /opt/bin/cks-config.py
270+
permissions: '0700'
271+
owner: root:root
272+
content: |
273+
#!/usr/bin/env python3
274+
import os
275+
import subprocess
276+
import sys
277+
import yaml
278+
279+
CKS_CONFIG = "#cks-config"
280+
KUBECTL_APPLY = "/opt/bin/kubectl apply -f"
281+
282+
def main(argv):
283+
if len(argv) < 1:
284+
print("YAML file is required")
285+
sys.exit(1)
286+
yaml_file=argv[0]
287+
if not os.path.exists(yaml_file):
288+
print("YAML file does not exist")
289+
sys.exit(1)
290+
with open(yaml_file) as f:
291+
head_line = f.readline().strip('\n')
292+
if head_line != CKS_CONFIG:
293+
command = "%s %s" % (KUBECTL_APPLY, yaml_file)
294+
run_command(command)
295+
sys.exit(0)
296+
297+
print("Applying CKS config file")
298+
content = yaml.safe_load(open(yaml_file))
299+
commands = content["commands"]
300+
if commands:
301+
for command in commands:
302+
run_command(command)
303+
304+
def run_command(command):
305+
try:
306+
print("Executing command: %s" % command)
307+
subprocess.check_output(command, shell=True, timeout=600)
308+
except subprocess.CalledProcessError as e:
309+
print("Error: %s " % e)
310+
sys.exit(1)
311+
312+
if __name__ == "__main__":
313+
main(sys.argv[1:])
267314
268315
- path: /opt/bin/deploy-kube-system
269316
permissions: '0700'
@@ -324,9 +371,9 @@ write_files:
324371
### Network, dashboard configs available offline ###
325372
echo "Offline configs are available!"
326373
if [[ ${EXTERNAL_CNI_PLUGIN} == false ]]; then
327-
/opt/bin/kubectl apply -f ${K8S_CONFIG_SCRIPTS_COPY_DIR}/network.yaml
374+
/opt/bin/cks-config.py ${K8S_CONFIG_SCRIPTS_COPY_DIR}/network.yaml
328375
fi
329-
/opt/bin/kubectl apply -f ${K8S_CONFIG_SCRIPTS_COPY_DIR}/dashboard.yaml
376+
/opt/bin/cks-config.py ${K8S_CONFIG_SCRIPTS_COPY_DIR}/dashboard.yaml
330377
rm -rf "${K8S_CONFIG_SCRIPTS_COPY_DIR}"
331378
else
332379
/opt/bin/kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(/opt/bin/kubectl version | base64 | tr -d '\n')"
@@ -374,6 +421,13 @@ write_files:
374421
Restart=on-failure
375422
ExecStart=/opt/bin/deploy-kube-system
376423
424+
- path: /etc/crictl.yaml
425+
permissions: '0700'
426+
owner: root:root
427+
content: |
428+
runtime-endpoint: unix:///var/run/containerd/containerd.sock
429+
image-endpoint: unix:///var/run/containerd/containerd.sock
430+
377431
runcmd:
378432
- chown -R cloud:cloud /home/cloud/.ssh
379433
- containerd config default > /etc/containerd/config.toml

plugins/integrations/kubernetes-service/src/main/resources/conf/k8s-node.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ write_files:
126126
echo "Installing binaries from ${BINARIES_DIR}"
127127
mkdir -p /opt/cni/bin
128128
tar -f "${BINARIES_DIR}/cni/cni-plugins-"*64.tgz -C /opt/cni/bin -xz
129+
chown -R root:root /opt/cni/bin/
129130
130131
mkdir -p /opt/bin
131132
tar -f "${BINARIES_DIR}/cri-tools/crictl-linux-"*64.tar.gz -C /opt/bin -xz
@@ -193,6 +194,7 @@ write_files:
193194
echo "Warning: ${BINARIES_DIR} not found. Will get binaries and docker images from Internet."
194195
mkdir -p /opt/cni/bin
195196
curl -L "https://github.com/containernetworking/plugins/releases/download/${CNI_VERSION}/cni-plugins-amd64-${CNI_VERSION}.tgz" | tar -C /opt/cni/bin -xz
197+
chown -R root:root /opt/cni/bin/
196198
197199
mkdir -p /opt/bin
198200
curl -L "https://github.com/kubernetes-incubator/cri-tools/releases/download/${CRICTL_VERSION}/crictl-${CRICTL_VERSION}-linux-amd64.tar.gz" | tar -C /opt/bin -xz
@@ -289,6 +291,13 @@ write_files:
289291
ExecStartPre=/usr/bin/curl -k https://{{ k8s_control_node.join_ip }}:6443/version
290292
ExecStart=/opt/bin/deploy-kube-system
291293
294+
- path: /etc/crictl.yaml
295+
permissions: '0700'
296+
owner: root:root
297+
content: |
298+
runtime-endpoint: unix:///var/run/containerd/containerd.sock
299+
image-endpoint: unix:///var/run/containerd/containerd.sock
300+
292301
runcmd:
293302
- chown -R cloud:cloud /home/cloud/.ssh
294303
- containerd config default > /etc/containerd/config.toml
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#cks-config
2+
images:
3+
- quay.io/cilium/cilium:v1.18.1
4+
- quay.io/cilium/operator-generic:v1.18.1
5+
- quay.io/cilium/cilium-envoy:v1.34.4-1754895458-68cffdfa568b6b226d70a7ef81fc65dda3b890bf
6+
commands:
7+
- curl -L https://github.com/cilium/cilium-cli/releases/download/v0.18.6/cilium-linux-amd64.tar.gz | tar -C /usr/bin -xz
8+
- sleep 1 && cilium install --version 1.18.1 --wait
9+
- sleep 1 && cilium status --wait
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#cks-config
2+
images:
3+
- kubernetesui/dashboard-api:1.13.0
4+
- kubernetesui/dashboard-auth:1.3.0
5+
- kubernetesui/dashboard-metrics-scraper:1.2.2
6+
- kubernetesui/dashboard-web:1.7.0
7+
- library/kong:3.8
8+
commands:
9+
- curl -fsSL https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash -s -- --version v3.19.0
10+
- helm repo add kubernetes-dashboard https://kubernetes.github.io/dashboard/
11+
- helm upgrade --install kubernetes-dashboard kubernetes-dashboard/kubernetes-dashboard --create-namespace --namespace kubernetes-dashboard --version 7.13.0

scripts/util/create-kubernetes-binaries-iso.sh

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
set -e
2020

2121
if [ $# -lt 6 ]; then
22-
echo "Invalid input. Valid usage: ./create-kubernetes-binaries-iso.sh OUTPUT_PATH KUBERNETES_VERSION CNI_VERSION CRICTL_VERSION WEAVENET_NETWORK_YAML_CONFIG DASHBOARD_YAML_CONFIG BUILD_NAME [ARCH] [ETCD_VERSION]"
22+
echo "Invalid input. Valid usage: ./create-kubernetes-binaries-iso.sh OUTPUT_PATH KUBERNETES_VERSION CNI_VERSION CRICTL_VERSION NETWORK_YAML_CONFIG DASHBOARD_YAML_CONFIG BUILD_NAME [ARCH] [ETCD_VERSION]"
2323
echo "eg: ./create-kubernetes-binaries-iso.sh ./ 1.11.4 0.7.1 1.11.1 https://github.com/weaveworks/weave/releases/download/latest_release/weave-daemonset-k8s-1.11.yaml https://raw.githubusercontent.com/kubernetes/dashboard/v1.10.0/src/deploy/recommended/kubernetes-dashboard.yaml setup-v1.11.4 amd64"
2424
exit 1
2525
fi
@@ -94,12 +94,20 @@ fi
9494
NETWORK_CONFIG_URL="${5}"
9595
echo "Downloading network config ${NETWORK_CONFIG_URL}"
9696
network_conf_file="${working_dir}/network.yaml"
97-
curl -sSL ${NETWORK_CONFIG_URL} -o ${network_conf_file}
97+
if [ -f "$NETWORK_CONFIG_URL" ];then
98+
cp "${NETWORK_CONFIG_URL}" ${network_conf_file}
99+
else
100+
curl -sSL ${NETWORK_CONFIG_URL} -o ${network_conf_file}
101+
fi
98102

99103
DASHBORAD_CONFIG_URL="${6}"
100104
echo "Downloading dashboard config ${DASHBORAD_CONFIG_URL}"
101105
dashboard_conf_file="${working_dir}/dashboard.yaml"
102-
curl -sSL ${DASHBORAD_CONFIG_URL} -o ${dashboard_conf_file}
106+
if [ -f "$DASHBORAD_CONFIG_URL" ];then
107+
cp "${DASHBORAD_CONFIG_URL}" ${dashboard_conf_file}
108+
else
109+
curl -sSL ${DASHBORAD_CONFIG_URL} -o ${dashboard_conf_file}
110+
fi
103111

104112
# TODO : Change the url once merged
105113
AUTOSCALER_URL="https://raw.githubusercontent.com/kubernetes/autoscaler/master/cluster-autoscaler/cloudprovider/cloudstack/examples/cluster-autoscaler-standard.yaml"
@@ -132,8 +140,15 @@ output=`${k8s_dir}/kubeadm config images list --kubernetes-version=${RELEASE}`
132140
# Don't forget about the yaml images !
133141
for i in ${network_conf_file} ${dashboard_conf_file}
134142
do
135-
images=`grep "image:" $i | cut -d ':' -f2- | tr -d ' ' | tr -d "'"`
136-
output=`printf "%s\n" ${output} ${images}`
143+
if grep "^#cks-config" $i;then
144+
images=$(python3 -c "import sys, yaml; [print(x) for x in yaml.safe_load(sys.stdin)['images']]" < $i)
145+
for image in ${images}; do
146+
output=`printf "%s\n" ${output} ${image}`
147+
done
148+
else
149+
images=`grep "image:" $i | cut -d ':' -f2- | tr -d ' ' | tr -d "'"`
150+
output=`printf "%s\n" ${output} ${images}`
151+
fi
137152
done
138153

139154
# Don't forget about the other image !
@@ -145,7 +160,7 @@ output=`printf "%s\n" ${output} ${provider_image}`
145160

146161
while read -r line; do
147162
echo "Downloading image $line ---"
148-
if [[ $line == kubernetesui* ]] || [[ $line == apache* ]] || [[ $line == weaveworks* ]]; then
163+
if [[ $line == kubernetesui* ]] || [[ $line == apache* ]] || [[ $line == weaveworks* ]] || [[ $line == library* ]]; then
149164
line="docker.io/${line}"
150165
fi
151166
sudo ctr image pull "$line"

0 commit comments

Comments
 (0)