-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #250 from cornelk/master
Add Kubernetes Dashboard addon
- Loading branch information
Showing
2 changed files
with
93 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package addons | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/xetys/hetzner-kube/pkg/clustermanager" | ||
) | ||
|
||
// DashboardAddon installs dashboard | ||
type DashboardAddon struct { | ||
masterNode *clustermanager.Node | ||
communicator clustermanager.NodeCommunicator | ||
} | ||
|
||
// NewDashboardAddon installs dashboard to the cluster | ||
func NewDashboardAddon(provider clustermanager.ClusterProvider, communicator clustermanager.NodeCommunicator) ClusterAddon { | ||
masterNode, _ := provider.GetMasterNode() | ||
return DashboardAddon{masterNode: masterNode, communicator: communicator} | ||
} | ||
|
||
func init() { | ||
addAddon(NewDashboardAddon) | ||
} | ||
|
||
// Name returns the addons name | ||
func (addon DashboardAddon) Name() string { | ||
return "dashboard" | ||
} | ||
|
||
// Requires returns a slice with the name of required addons | ||
func (addon DashboardAddon) Requires() []string { | ||
return []string{} | ||
} | ||
|
||
// Description returns the addons description | ||
func (addon DashboardAddon) Description() string { | ||
return "Kubernetes Dashboard" | ||
} | ||
|
||
// URL returns the URL of the addons underlying project | ||
func (addon DashboardAddon) URL() string { | ||
return "https://github.com/kubernetes/dashboard" | ||
} | ||
|
||
// Install performs all steps to install the addon | ||
func (addon DashboardAddon) Install(args ...string) { | ||
node := *addon.masterNode | ||
_, err := addon.communicator.RunCmd(node, "kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v1.10.1/src/deploy/recommended/kubernetes-dashboard.yaml") | ||
FatalOnError(err) | ||
|
||
serviceAccount := `apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: admin-user | ||
namespace: kube-system | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1beta1 | ||
kind: ClusterRoleBinding | ||
metadata: | ||
name: admin-user | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: ClusterRole | ||
name: cluster-admin | ||
subjects: | ||
- kind: ServiceAccount | ||
name: admin-user | ||
namespace: kube-system` | ||
err = addon.communicator.WriteFile(node, "/root/dashboard-service-account.yaml", serviceAccount, false) | ||
FatalOnError(err) | ||
|
||
_, err = addon.communicator.RunCmd(node, "kubectl apply -f dashboard-service-account.yaml") | ||
FatalOnError(err) | ||
|
||
token, err := addon.communicator.RunCmd(node, "kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep admin-user | awk '{print $1}') | grep -E '^token' | cut -f2 -d':' | tr -d ' \t'") | ||
FatalOnError(err) | ||
|
||
fmt.Printf("Use the following token to login to the dashboard: %s\n", token) | ||
fmt.Println("Dashboard installed") | ||
} | ||
|
||
// Uninstall performs all steps to remove the addon | ||
func (addon DashboardAddon) Uninstall() { | ||
node := *addon.masterNode | ||
_, err := addon.communicator.RunCmd(node, "kubectl delete -f https://raw.githubusercontent.com/kubernetes/dashboard/v1.10.1/src/deploy/recommended/kubernetes-dashboard.yaml") | ||
FatalOnError(err) | ||
|
||
_, err = addon.communicator.RunCmd(node, "kubectl delete -f dashboard-service-account.yaml") | ||
FatalOnError(err) | ||
|
||
fmt.Println("Dashboard uninstalled") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters