From dbd958d31d9b805e21882c0a9cfe1cbb7a5e473d Mon Sep 17 00:00:00 2001 From: archyufa Date: Tue, 13 Sep 2016 14:33:55 -0400 Subject: [PATCH] [k8s] Add Dashboard UI v1.4 addon to K8s Cluster This patch introduces kubernetes-dashboard addon to k8s murano application. By default this option is enabled, but user can disable it in dynamic UI corresponding form Co-Authored-By: ddovbii Change-Id: Id03aed1c5e3c356421beef7b5110d03c2f07d47d --- .../package/Classes/KubernetesCluster.yaml | 32 +++++++++ .../Resources/DeployDashboard.template | 32 +++++++++ .../scripts/addons/kube-dashboard-addon.yaml | 70 +++++++++++++++++++ .../Resources/scripts/deployDashboard.sh | 9 +++ .../package/Resources/scripts/haproxy.tmpl | 16 +++++ .../KubernetesCluster/package/UI/ui.yaml | 8 +++ ...kube-dashboard-addon-fd9f4858a25f301d.yaml | 8 +++ 7 files changed, 175 insertions(+) create mode 100644 Kubernetes/KubernetesCluster/package/Resources/DeployDashboard.template create mode 100644 Kubernetes/KubernetesCluster/package/Resources/scripts/addons/kube-dashboard-addon.yaml create mode 100644 Kubernetes/KubernetesCluster/package/Resources/scripts/deployDashboard.sh create mode 100644 releasenotes/notes/kube-dashboard-addon-fd9f4858a25f301d.yaml diff --git a/Kubernetes/KubernetesCluster/package/Classes/KubernetesCluster.yaml b/Kubernetes/KubernetesCluster/package/Classes/KubernetesCluster.yaml index 9930e67..2cebc95 100644 --- a/Kubernetes/KubernetesCluster/package/Classes/KubernetesCluster.yaml +++ b/Kubernetes/KubernetesCluster/package/Classes/KubernetesCluster.yaml @@ -55,6 +55,10 @@ Properties: Contract: $.bool().notNull() Default: true + enableDashboard: + Contract: $.bool().notNull() + Default: true + dockerRegistry: Contract: $.string() @@ -152,11 +156,22 @@ Methods: Then: $._deployDns() + - If: $.enableDashboard + Then: + - $._deployDashboard() + - If: $.gatewayCount > 0 + Then: + - $msg: $.gatewayNodes.take($.gatewayCount).select('http://{0}:{1}'.format($.getIp(true), 9090)).join(', ') + - $._environment.reporter.report($this, 'Dashboard UI is available at {0}'.format($msg)) + Else: + - $._environment.reporter.report($this, 'Dashboard UI is installed but is not accessible from outside') + - $._environment.stack.push() - $._updateServicePublicIps() - $.setAttr(lastNodeCount, $.nodeCount) - $.setAttr(lastGatewayCount, $.gatewayCount) - $._environment.reporter.report($this, 'Kubernetes cluster is up and running') + - $.setAttr(serviceEndpoints, $.serviceEndpoints) @@ -165,6 +180,23 @@ Methods: Return: $.masterNode.getIp() + _deployDashboard: + Body: + - If: not $.getAttr(uiDeployed, false) + Then: + - $securityGroupIngress: + - ToPort: 9090 + FromPort: 9090 + IpProtocol: tcp + External: $.masterNode.instance.assignFloatingIp + - $._environment.securityGroupManager.addGroupIngress($securityGroupIngress) + + - $resources: new(sys:Resources) + - $template: $resources.yaml('DeployDashboard.template').bind(dict(ip => $.getIp())) + - $.masterNode.instance.agent.call($template, $resources) + - $.setAttr(uiDeployed, true) + + _deployDns: Body: - If: not $.getAttr(dnsDeployed, false) diff --git a/Kubernetes/KubernetesCluster/package/Resources/DeployDashboard.template b/Kubernetes/KubernetesCluster/package/Resources/DeployDashboard.template new file mode 100644 index 0000000..be13053 --- /dev/null +++ b/Kubernetes/KubernetesCluster/package/Resources/DeployDashboard.template @@ -0,0 +1,32 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +FormatVersion: 2.0.0 +Version: 1.0.0 +Name: Deploy Dashboard + +Parameters: + ip: $ip + +Body: | + return deploy('{0}'.format(args.ip)).stdout + +Scripts: + deploy: + Type: Application + Version: 1.0.0 + EntryPoint: deployDashboard.sh + Files: + - addons/kube-dashboard-addon.yaml + Options: + captureStdout: true + captureStderr: true diff --git a/Kubernetes/KubernetesCluster/package/Resources/scripts/addons/kube-dashboard-addon.yaml b/Kubernetes/KubernetesCluster/package/Resources/scripts/addons/kube-dashboard-addon.yaml new file mode 100644 index 0000000..d0d0b4f --- /dev/null +++ b/Kubernetes/KubernetesCluster/package/Resources/scripts/addons/kube-dashboard-addon.yaml @@ -0,0 +1,70 @@ +# Copyright 2016 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Configuration to deploy release version of the Dashboard UI. +# +# Example usage: kubectl create -f + +kind: Service +apiVersion: v1 +metadata: + labels: + app: kubernetes-dashboard + name: kubernetes-dashboard + namespace: kube-system +spec: + type: ClusterIP + ports: + - port: 9090 + targetPort: 9090 + selector: + app: kubernetes-dashboard + +--- + +kind: Deployment +apiVersion: extensions/v1beta1 +metadata: + labels: + app: kubernetes-dashboard + name: kubernetes-dashboard + namespace: kube-system +spec: + replicas: 1 + selector: + matchLabels: + app: kubernetes-dashboard + template: + metadata: + labels: + app: kubernetes-dashboard + spec: + containers: + - name: kubernetes-dashboard + image: gcr.io/google_containers/kubernetes-dashboard-amd64:v1.4.0 + imagePullPolicy: Always + ports: + - containerPort: 9090 + protocol: TCP + args: + # Uncomment the following line to manually specify Kubernetes API server Host + # If not specified, Dashboard will attempt to auto discover the API server and connect + # to it. Uncomment only if the default does not work. + - --apiserver-host=http://%%MASTER_IP%%:8080 + livenessProbe: + httpGet: + path: / + port: 9090 + initialDelaySeconds: 30 + timeoutSeconds: 30 diff --git a/Kubernetes/KubernetesCluster/package/Resources/scripts/deployDashboard.sh b/Kubernetes/KubernetesCluster/package/Resources/scripts/deployDashboard.sh new file mode 100644 index 0000000..9514a7e --- /dev/null +++ b/Kubernetes/KubernetesCluster/package/Resources/scripts/deployDashboard.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +# $1 - IP + +sed -i.bak "s/%%MASTER_IP%%/$1/g" addons/kube-dashboard-addon.yaml + +cp -f addons/kube-dashboard-addon.yaml /etc/kubernetes/addons + +/opt/bin/kubectl create -f /etc/kubernetes/addons/kube-dashboard-addon.yaml >> /tmp/murano-kube.log \ No newline at end of file diff --git a/Kubernetes/KubernetesCluster/package/Resources/scripts/haproxy.tmpl b/Kubernetes/KubernetesCluster/package/Resources/scripts/haproxy.tmpl index 178cb85..6e04004 100644 --- a/Kubernetes/KubernetesCluster/package/Resources/scripts/haproxy.tmpl +++ b/Kubernetes/KubernetesCluster/package/Resources/scripts/haproxy.tmpl @@ -5,6 +5,22 @@ defaults contimeout 5000 clitimeout 50000 srvtimeout 50000 + +#Template for kubernetes-dashboard addon +{{$svc := "/registry/services/endpoints/kube-system/kubernetes-dashboard"}} +{{if exists $svc}} +{{$uiEndpoint := get $svc}} +{{$uiSpec := get "/registry/services/specs/kube-system/kubernetes-dashboard"}} +{{$uiEndpointJson := json $uiEndpoint.Value}}{{$uiSpecJson := json $uiSpec.Value}} +{{range $port := $uiSpecJson.spec.ports}} +listen kubernetes-dashboard-{{$port.port}} 0.0.0.0:{{$port.port}} + mode tcp + balance leastconn +{{range $subset := $uiEndpointJson.subsets}}{{range $index, $endpoint := $subset.addresses}} + server srv{{$index}} {{$endpoint.ip}}:{{$port.targetPort}} +{{end}}{{end}}{{end}}{{end}} + +#Template for the rest of services located in default namespace {{range $svc := ls "/registry/services/endpoints/default"}} {{$se := printf "/registry/services/endpoints/default/%s" $svc }} {{$ss := printf "/registry/services/specs/default/%s" $svc }} diff --git a/Kubernetes/KubernetesCluster/package/UI/ui.yaml b/Kubernetes/KubernetesCluster/package/UI/ui.yaml index f57ed76..719f8b8 100644 --- a/Kubernetes/KubernetesCluster/package/UI/ui.yaml +++ b/Kubernetes/KubernetesCluster/package/UI/ui.yaml @@ -67,6 +67,7 @@ Application: dockerMirror: $.kubeNetConfiguration.dockerMirror gcloudKey: $.kubeNetConfiguration.gcloudKey enableKubeDns: $.kubeNetConfiguration.enableKubeDns + enableDashboard: $.kubeNetConfiguration.enableDashboard Forms: - nodesConfiguration: @@ -180,6 +181,13 @@ Forms: description: >- Check, if you are going to use KubeDNS feature in your cluster required: false + - name: enableDashboard + type: boolean + initial: true + label: Enable Kubernetes Dashboard addon + description: >- + Check, if you are going to use Kubernetes Dashboard in your cluster + required: false - name: dockerRegistry type: string label: Custom Docker registry URL diff --git a/releasenotes/notes/kube-dashboard-addon-fd9f4858a25f301d.yaml b/releasenotes/notes/kube-dashboard-addon-fd9f4858a25f301d.yaml new file mode 100644 index 0000000..f4245b8 --- /dev/null +++ b/releasenotes/notes/kube-dashboard-addon-fd9f4858a25f301d.yaml @@ -0,0 +1,8 @@ +--- +features: + - Now Kubernetes Cluster murano application provides ability to install + Kubernetes Dashbord addon v1.4 during cluster deployment. + Dashboard (the web-based user interface of Kubernetes) allows user + to deploy containerized applications to a Kubernetes cluster, troubleshoot + them, and manage the cluster and its resources itself. + User can find dashbord endpoint in deployment logs.