Skip to content

Commit 7db663b

Browse files
committed
Add support for Headlamp dashboard for kubernetes; deprecate legacy kubernetes dashboard
1 parent 74af9b9 commit 7db663b

File tree

4 files changed

+85
-13
lines changed

4 files changed

+85
-13
lines changed

plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/utils/KubernetesClusterUtil.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,20 @@ public static boolean isKubernetesClusterDashboardServiceRunning(final Kubernete
171171
// Check if dashboard service is up running.
172172
while (System.currentTimeMillis() < timeoutTime) {
173173
if (LOGGER.isDebugEnabled()) {
174-
LOGGER.debug(String.format("Checking dashboard service for the Kubernetes cluster: %s to come up", kubernetesCluster));
174+
LOGGER.debug(String.format("Checking dashboard service (Kubernetes Dashboard or Headlamp) for the Kubernetes cluster: %s to come up", kubernetesCluster));
175175
}
176+
// Check for Headlamp (new dashboard) in kube-system namespace
177+
if (isKubernetesClusterAddOnServiceRunning(kubernetesCluster, ipAddress, port, user, sshKeyFile, "kube-system", "headlamp")) {
178+
if (LOGGER.isInfoEnabled()) {
179+
LOGGER.info(String.format("Headlamp dashboard service for the Kubernetes cluster %s is in running state", kubernetesCluster));
180+
}
181+
running = true;
182+
break;
183+
}
184+
// For backward compatibility, check for Kubernetes Dashboard in kubernetes-dashboard namespace
176185
if (isKubernetesClusterAddOnServiceRunning(kubernetesCluster, ipAddress, port, user, sshKeyFile, "kubernetes-dashboard", "kubernetes-dashboard")) {
177186
if (LOGGER.isInfoEnabled()) {
178-
LOGGER.info(String.format("Dashboard service for the Kubernetes cluster %s is in running state", kubernetesCluster));
187+
LOGGER.info(String.format("Kubernetes Dashboard service for the Kubernetes cluster %s is in running state", kubernetesCluster));
179188
}
180189
running = true;
181190
break;

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,16 +331,29 @@ write_files:
331331
if [[ ${EXTERNAL_CNI_PLUGIN} == false ]]; then
332332
/opt/bin/kubectl apply -f ${K8S_CONFIG_SCRIPTS_COPY_DIR}/network.yaml
333333
fi
334-
/opt/bin/kubectl apply -f ${K8S_CONFIG_SCRIPTS_COPY_DIR}/dashboard.yaml
334+
if [ -f "${K8S_CONFIG_SCRIPTS_COPY_DIR}/headlamp.yaml" ]; then
335+
echo "Installing Headlamp dashboard from ISO"
336+
/opt/bin/kubectl apply -f ${K8S_CONFIG_SCRIPTS_COPY_DIR}/headlamp.yaml
337+
elif [ -f "${K8S_CONFIG_SCRIPTS_COPY_DIR}/dashboard.yaml" ]; then
338+
echo "Installing Kubernetes Dashboard from ISO"
339+
/opt/bin/kubectl apply -f ${K8S_CONFIG_SCRIPTS_COPY_DIR}/dashboard.yaml
340+
/opt/bin/kubectl create rolebinding admin-binding --role=admin --user=admin || true
341+
/opt/bin/kubectl create clusterrolebinding cluster-admin-binding --clusterrole=cluster-admin --user=admin || true
342+
/opt/bin/kubectl create clusterrolebinding kubernetes-dashboard-ui --clusterrole=cluster-admin --serviceaccount=kubernetes-dashboard:kubernetes-dashboard || true
343+
else
344+
echo "Warning: No dashboard YAML found in ISO (neither headlamp.yaml nor dashboard.yaml)"
345+
fi
335346
rm -rf "${K8S_CONFIG_SCRIPTS_COPY_DIR}"
336347
else
348+
### Online installation - use Headlamp by default ###
337349
/opt/bin/kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(/opt/bin/kubectl version | base64 | tr -d '\n')"
338-
/opt/bin/kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0-beta6/aio/deploy/recommended.yaml
350+
/opt/bin/kubectl apply -f https://raw.githubusercontent.com/kubernetes-sigs/headlamp/v0.40.1/kubernetes-headlamp.yaml
351+
/opt/bin/kubectl create serviceaccount headlamp-admin -n kube-system || true
352+
/opt/bin/kubectl create clusterrolebinding headlamp-admin --clusterrole=cluster-admin --serviceaccount=kube-system:headlamp-admin || true
339353
fi
340354
341355
/opt/bin/kubectl create rolebinding admin-binding --role=admin --user=admin || true
342356
/opt/bin/kubectl create clusterrolebinding cluster-admin-binding --clusterrole=cluster-admin --user=admin || true
343-
/opt/bin/kubectl create clusterrolebinding kubernetes-dashboard-ui --clusterrole=cluster-admin --serviceaccount=kubernetes-dashboard:kubernetes-dashboard || true
344357
345358
sudo touch /home/cloud/success
346359
echo "true" > /home/cloud/success

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

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
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]"
23-
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"
22+
echo "Invalid input. Valid usage: ./create-kubernetes-binaries-iso.sh OUTPUT_PATH KUBERNETES_VERSION CNI_VERSION CRICTL_VERSION WEAVENET_NETWORK_YAML_CONFIG HEADLAMP_DASHBOARD_VERSION BUILD_NAME [ARCH] [ETCD_VERSION]"
23+
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 0.40.1 setup-v1.11.4 amd64"
2424
exit 1
2525
fi
2626

@@ -96,10 +96,60 @@ echo "Downloading network config ${NETWORK_CONFIG_URL}"
9696
network_conf_file="${working_dir}/network.yaml"
9797
curl -sSL ${NETWORK_CONFIG_URL} -o ${network_conf_file}
9898

99-
DASHBORAD_CONFIG_URL="${6}"
100-
echo "Downloading dashboard config ${DASHBORAD_CONFIG_URL}"
101-
dashboard_conf_file="${working_dir}/dashboard.yaml"
102-
curl -sSL ${DASHBORAD_CONFIG_URL} -o ${dashboard_conf_file}
99+
HEADLAMP_DASHBOARD_VERSION="${6}"
100+
HEADLAMP_DASHBOARD_URL="https://raw.githubusercontent.com/kubernetes-sigs/headlamp/v${HEADLAMP_DASHBOARD_VERSION}/kubernetes-headlamp.yaml"
101+
echo "Downloading Headlamp manifest from ${HEADLAMP_DASHBOARD_URL}"
102+
headlamp_conf_file="${working_dir}/headlamp.yaml"
103+
curl -sSL ${HEADLAMP_DASHBOARD_URL} -o ${headlamp_conf_file}
104+
105+
# Patch the Headlamp manifest to add missing components
106+
echo "Patching Headlamp manifest with missing ServiceAccount and ClusterRoleBinding..."
107+
108+
if ! grep -q "kind: ServiceAccount" ${headlamp_conf_file}; then
109+
echo "Adding missing ServiceAccount to Headlamp manifest"
110+
cat > ${headlamp_conf_file}.tmp << 'EOF'
111+
---
112+
# ServiceAccount for Headlamp (added by CloudStack)
113+
kind: ServiceAccount
114+
apiVersion: v1
115+
metadata:
116+
name: headlamp-admin
117+
namespace: kube-system
118+
---
119+
# ClusterRoleBinding to grant cluster-admin permissions to Headlamp (added by CloudStack)
120+
kind: ClusterRoleBinding
121+
apiVersion: rbac.authorization.k8s.io/v1
122+
metadata:
123+
name: headlamp-admin
124+
roleRef:
125+
apiGroup: rbac.authorization.k8s.io
126+
kind: ClusterRole
127+
name: cluster-admin
128+
subjects:
129+
- kind: ServiceAccount
130+
name: headlamp-admin
131+
namespace: kube-system
132+
---
133+
EOF
134+
cat ${headlamp_conf_file} >> ${headlamp_conf_file}.tmp
135+
mv ${headlamp_conf_file}.tmp ${headlamp_conf_file}
136+
fi
137+
138+
if grep -q "kind: Deployment" ${headlamp_conf_file} && ! grep -q "serviceAccountName:" ${headlamp_conf_file}; then
139+
echo "Adding serviceAccountName to Headlamp Deployment"
140+
awk '/kind: Deployment/,0 {
141+
if (/^ spec:$/ && !found) {
142+
print
143+
print " serviceAccountName: headlamp-admin"
144+
found=1
145+
next
146+
}
147+
}
148+
{print}' ${headlamp_conf_file} > ${headlamp_conf_file}.tmp
149+
mv ${headlamp_conf_file}.tmp ${headlamp_conf_file}
150+
fi
151+
152+
echo "Headlamp manifest patched successfully"
103153

104154
# TODO : Change the url once merged
105155
AUTOSCALER_URL="https://raw.githubusercontent.com/kubernetes/autoscaler/master/cluster-autoscaler/cloudprovider/cloudstack/examples/cluster-autoscaler-standard.yaml"
@@ -135,7 +185,7 @@ mkdir -p "${working_dir}/docker"
135185
output=`${k8s_dir}/kubeadm config images list --kubernetes-version=${RELEASE}`
136186

137187
# Don't forget about the yaml images !
138-
for i in ${network_conf_file} ${dashboard_conf_file}
188+
for i in ${network_conf_file} ${headlamp_conf_file}
139189
do
140190
images=`grep "image:" $i | cut -d ':' -f2- | tr -d ' ' | tr -d "'"`
141191
output=`printf "%s\n" ${output} ${images}`

ui/src/views/compute/KubernetesServiceTab.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
<a-timeline-item>
8888
<p>
8989
{{ $t('label.token.for.dashboard.login') }}<br><br>
90-
<code><b>kubectl --kubeconfig /custom/path/kube.conf describe secret $(kubectl --kubeconfig /custom/path/kube.conf get secrets -n kubernetes-dashboard | grep kubernetes-dashboard-token | awk '{print $1}') -n kubernetes-dashboard</b></code>
90+
<code><b>kubectl --kubeconfig /custom/path/kube.conf describe secret $(kubectl --kubeconfig /custom/path/kube.conf get secrets -n kube-system | grep headlamp-admin | awk '{print $1}') -n kube-system</b></code>
9191
</p>
9292
</a-timeline-item>
9393
</a-timeline>

0 commit comments

Comments
 (0)