@@ -58,6 +58,9 @@ required binaries:
58
58
case "ingress" :
59
59
installIngress ()
60
60
return
61
+ case "monitoring" :
62
+ installMonitoring ()
63
+ return
61
64
case "kubernetes" :
62
65
installKubernetes ()
63
66
checkCluster ()
@@ -71,6 +74,7 @@ required binaries:
71
74
installMetrics ()
72
75
installCertManager ()
73
76
installKuberoOperator ()
77
+ installMonitoring ()
74
78
installKuberoUi ()
75
79
writeCLIconfig ()
76
80
printDNSinfo ()
@@ -91,13 +95,14 @@ var arg_portSecure string
91
95
var clusterType string
92
96
var arg_component string
93
97
var install_olm bool
98
+ var monitoringInstalled bool
94
99
var ingressControllerVersion = "v1.10.0" // https://github.com/kubernetes/ingress-nginx/tags -> controller-v1.5.1
95
100
96
101
// var clusterTypeSelection = "[scaleway,linode,gke,digitalocean,kind]"
97
102
var clusterTypeList = []string {"kind" , "linode" , "scaleway" , "gke" , "digitalocean" }
98
103
99
104
func init () {
100
- installCmd .Flags ().StringVarP (& arg_component , "component" , "c" , "" , "install component (kubernetes,olm,ingress,metrics,certmanager,kubero-operator,kubero-ui)" )
105
+ installCmd .Flags ().StringVarP (& arg_component , "component" , "c" , "" , "install component (kubernetes,olm,ingress,metrics,certmanager,kubero-operator,monitoring, kubero-ui)" )
101
106
installCmd .Flags ().StringVarP (& arg_adminUser , "user" , "u" , "" , "Admin username for the kubero UI" )
102
107
installCmd .Flags ().StringVarP (& arg_adminPassword , "user-password" , "U" , "" , "Password for the admin user" )
103
108
installCmd .Flags ().StringVarP (& arg_apiToken , "apitoken" , "a" , "" , "API token for the admin user" )
@@ -107,6 +112,7 @@ func init() {
107
112
rootCmd .AddCommand (installCmd )
108
113
109
114
install_olm = false
115
+ monitoringInstalled = false
110
116
}
111
117
112
118
func checkAllBinaries () {
@@ -140,8 +146,9 @@ func printInstallSteps() {
140
146
4. Install the metrics server {{(optional, but recommended)}}::gray
141
147
5. Install the cert-manager {{(optional)}}::gray
142
148
6. Install the kubero operator {{(required)}}::gray
143
- 7. Install the kubero UI {{(optional, but highly recommended)}}::gray
144
- 8. Write the kubero CLI config
149
+ 7. Install the monitoring stack {{(optional, but recommended)}}::gray
150
+ 8. Install the kubero UI {{(optional, but highly recommended)}}::gray
151
+ 9. Write the kubero CLI config
145
152
` )
146
153
}
147
154
@@ -378,6 +385,72 @@ func installIngress() {
378
385
ingressSpinner .Error ("Failed to run command. Try runnig this command manually: kubectl apply -f " + URL )
379
386
log .Fatal (ingressErr )
380
387
}
388
+
389
+ patch := `{
390
+ "spec": {
391
+ "template": {
392
+ "metadata": {
393
+ "annotations": {
394
+ "prometheus.io/port": "10254",
395
+ "prometheus.io/scrape": "true"
396
+ }
397
+ },
398
+ "spec": {
399
+ "containers": [
400
+ {
401
+ "name": "controller",
402
+ "ports": [
403
+ {
404
+ "containerPort": 10254,
405
+ "name": "prometheus",
406
+ "protocol": "TCP"
407
+ }
408
+ ],
409
+ "args": [
410
+ "/nginx-ingress-controller",
411
+ "--election-id=ingress-nginx-leader",
412
+ "--controller-class=k8s.io/ingress-nginx",
413
+ "--ingress-class=nginx",
414
+ "--configmap=$(POD_NAMESPACE)/ingress-nginx-controller",
415
+ "--validating-webhook=:8443",
416
+ "--validating-webhook-certificate=/usr/local/certificates/cert",
417
+ "--validating-webhook-key=/usr/local/certificates/key",
418
+ "--watch-ingress-without-class=true",
419
+ "--enable-metrics=true",
420
+ "--publish-status-address=localhost"
421
+ ]
422
+ }
423
+ ]
424
+ }
425
+ }
426
+ }
427
+ }`
428
+ _ , ingressPatch := exec .Command ("kubectl" , "patch" , "deployments.apps" , "ingress-nginx-controller" , "-n" , "ingress-nginx" , "-p" , patch ).Output ()
429
+ if ingressPatch != nil {
430
+ ingressSpinner .Error ("Failed to patch the ingress controller. Here is a detailled information how to do it manually: https://github.com/kubernetes/ingress-nginx/blob/main/docs/user-guide/monitoring.md" )
431
+ //log.Fatal(ingressPatch)
432
+ }
433
+
434
+ patch = `{
435
+ "spec": {
436
+ "ports": [
437
+ {
438
+ "name": "prometheus",
439
+ "nodePort": 31280,
440
+ "port": 10254,
441
+ "protocol": "TCP",
442
+ "targetPort": "prometheus"
443
+ }
444
+ ]
445
+ }
446
+ }`
447
+
448
+ _ , ingressPatch = exec .Command ("kubectl" , "patch" , "svc" , "ingress-nginx-controller" , "-n" , "ingress-nginx" , "-p" , patch ).Output ()
449
+ if ingressPatch != nil {
450
+ ingressSpinner .Error ("Failed to patch the ingress controller service. Here is a detailled information how to do it manually: https://github.com/kubernetes/ingress-nginx/blob/main/docs/user-guide/monitoring.md" )
451
+ //log.Fatal(ingressPatch)
452
+ }
453
+
381
454
ingressSpinner .Success ("Ingress installed sucessfully" )
382
455
}
383
456
@@ -446,25 +519,30 @@ func installKuberoOperatorSlim() {
446
519
447
520
}
448
521
449
- func installKuberoUi ( ) {
522
+ func createNamespace ( namespace string ) {
450
523
451
- ingressInstall := promptLine ("7) Install Kubero UI" , "[y,n]" , "y" )
452
- if ingressInstall != "y" {
453
- return
454
- }
455
-
456
- kuberoNSinstalled , _ := exec .Command ("kubectl" , "get" , "ns" , "kubero" ).Output ()
524
+ kuberoNSinstalled , _ := exec .Command ("kubectl" , "get" , "ns" , namespace ).Output ()
457
525
if len (kuberoNSinstalled ) > 0 {
458
- cfmt .Println ("{{✓ Kubero Namespace exists}}::lightGreen" )
526
+ cfmt .Printf ("{{✓ Namespace %s exists}}::lightGreen\n " , namespace )
459
527
} else {
460
- _ , kuberoNSErr := exec .Command ("kubectl" , "create" , "namespace" , "kubero" ).Output ()
528
+ _ , kuberoNSErr := exec .Command ("kubectl" , "create" , "namespace" , namespace ).Output ()
461
529
if kuberoNSErr != nil {
462
- fmt .Println ("Failed to run command to create the namespace. Try runnig this command manually: kubectl create namespace kubero" )
530
+ fmt .Println ("Failed to run command to create the namespace. Try runnig this command manually: kubectl create namespace " + namespace )
463
531
log .Fatal (kuberoNSErr )
464
532
} else {
465
- cfmt .Println ("{{✓ Kubero Namespace created}}::lightGreen" )
533
+ cfmt .Printf ("{{✓ Namespace %s created}}::lightGreen\n " , namespace )
466
534
}
467
535
}
536
+ }
537
+
538
+ func installKuberoUi () {
539
+
540
+ ingressInstall := promptLine ("7) Install Kubero UI" , "[y,n]" , "y" )
541
+ if ingressInstall != "y" {
542
+ return
543
+ }
544
+
545
+ createNamespace ("kubero" )
468
546
469
547
kuberoSecretInstalled , _ := exec .Command ("kubectl" , "get" , "secret" , "kubero-secrets" , "-n" , "kubero" ).Output ()
470
548
if len (kuberoSecretInstalled ) > 0 {
@@ -636,7 +714,14 @@ func installKuberoUi() {
636
714
637
715
}
638
716
639
- kuberoUIconsole := promptLine ("Enable Console Access to running containers" , "[y/n]" , "n" )
717
+ if monitoringInstalled {
718
+ kuberoUIConfig .Spec .Prometheus .Enabled = true
719
+ kuberoUIConfig .Spec .Prometheus .Endpoint = promptLine ("Prometheus URL" , "" , "http://kubero-prometheus-server" )
720
+ } else {
721
+ kuberoUIConfig .Spec .Prometheus .Enabled = false
722
+ }
723
+
724
+ kuberoUIconsole := promptLine ("Enable Console Access to running containers" , "[y/n]" , "y" )
640
725
641
726
if kuberoUIconsole == "y" {
642
727
kuberoUIConfig .Spec .Kubero .Config .Kubero .Console .Enabled = true
@@ -700,6 +785,61 @@ func installKuberoUi() {
700
785
701
786
}
702
787
788
+ func installMonitoring () {
789
+
790
+ if promptLine ("Enable longterm metrics" , "[y/n]" , "y" ) == "y" {
791
+ monitoringInstalled = true
792
+ } else {
793
+ monitoringInstalled = false
794
+ return
795
+ }
796
+
797
+ createNamespace ("kubero" )
798
+
799
+ spinner := spinner .New ("enable metrics" )
800
+ if promptLine ("Create local Prometheus instance" , "[y/n]" , "y" ) == "y" {
801
+ URL := "https://raw.githubusercontent.com/kubero-dev/kubero-operator/main/config/samples/application_v1alpha1_kuberoprometheus.yaml"
802
+ spinner .Start ("run command : kubectl apply -f " + URL )
803
+ _ , ingressErr := exec .Command ("kubectl" , "apply" , "-n" , "kubero" , "-f" , URL ).Output ()
804
+ if ingressErr != nil {
805
+ spinner .Error ("Failed to run command. Try runnig this command manually: kubectl apply -f " + URL )
806
+ log .Fatal (ingressErr )
807
+ }
808
+
809
+ spinner .UpdateMessage ("Waiting for Prometheus to be ready" )
810
+
811
+ time .Sleep (5 * time .Second )
812
+ // kubectl wait --for=condition=available deployment/kubero -n kubero --timeout=180s
813
+ _ , olmWaitErr := exec .Command ("kubectl" , "wait" , "--for=condition=available" , "deployment/kubero-prometheus-server" , "-n" , "kubero" , "--timeout=180s" ).Output ()
814
+ if olmWaitErr != nil {
815
+ spinner .Error ("Failed to wait for Prometheus to become ready" )
816
+ log .Fatal (olmWaitErr )
817
+ }
818
+ spinner .Success ("Prometheus installed sucessfully" )
819
+ }
820
+
821
+ if promptLine ("Enable Kubemetrtics" , "[y/n]" , "y" ) == "y" {
822
+ spinner .Start ("run command : kubectl patch kuberoes kubero -n kubero --type=merge" )
823
+
824
+ patch := `{
825
+ "spec": {
826
+ "prometheus": {
827
+ "kube-state-metrics": {
828
+ "enabled": true
829
+ }
830
+ }
831
+ }
832
+ }`
833
+
834
+ _ , patchResult := exec .Command ("kubectl" , "patch" , "kuberoprometheuses" , "kubero-prometheus" , "-n" , "kubero" , "--type=merge" , "-p" , patch ).Output ()
835
+ if patchResult != nil {
836
+ spinner .Error ("Failed to patch the kubero prometheus CRD to enable kube metrics" , patchResult .Error (), patch )
837
+ }
838
+ spinner .Success ("metrics enabled sucessfully" )
839
+
840
+ }
841
+ }
842
+
703
843
func installCertManager () {
704
844
705
845
install := promptLine ("5) Install SSL Certmanager" , "[y,n]" , "y" )
0 commit comments