forked from logzio/logzio-helm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
quickstart-metrics.sh
executable file
·119 lines (101 loc) · 4.36 KB
/
quickstart-metrics.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/bin/bash
echo "Checking for installed prerequisites.."
echo -n "Checking for kubectl ............. "
has_kubectl=$(kubectl 2>&1)
if [[ $has_kubectl == *"command not found"* ]]; then
echo -n "kubectl not found! Please install and configure kubectl first."
exit 1
fi
echo "Passed"
echo -n "Checking for jq ............. "
has_jq=$(jq --version 2>&1)
if [[ $has_jq == *"not found"* ]]; then
if [[ "$OSTYPE" == "linux-gnu" ]]; then
sudo apt-get install jq
elif [[ "$OSTYPE" == "darwin"* ]]; then
brew install jq
else
echo -n "This OS is not supported by this installation script. Please follow the manual instructions at https://docs.logz.io/shipping/metrics-sources/kubernetes.html"
exit 1
fi
fi
echo "Passed"
echo -n "Checking for helm ............. "
has_helm=$(helm version 2>&1)
if [[ $has_helm == *"not found"* ]]; then
curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash
fi
echo "Passed"
echo -n "Checking for kubectl ............. "
has_kube_stat_metrics=$(kubectl get deployments --all-namespaces | grep kube-state-metrics)
if [[ -z $has_kube_stat_metrics ]]; then
echo "ERROR: kube-state-metrics is not deployed in your cluster. Please deploy it from https://github.com/kubernetes/kube-state-metrics and run this script again"
exit 1
fi
echo "Passed"
kube_stat_ns=$(kubectl get deployments --all-namespaces -o json | jq '.items[] | select(.metadata.name == "kube-state-metrics")' | jq -r '.metadata.namespace')
kube_stat_port=$(kubectl get deployments --all-namespaces -o json | jq '.items[] | select(.metadata.name == "kube-state-metrics")' | jq '.spec.template.spec.containers[0].ports[] | select(.name == "http-metrics")' | jq '.containerPort')
configmap_api=$(kubectl explain configmap | awk 'NR==2')
configmap_api=${configmap_api:10}
daemonset_api=$(kubectl explain daemonset | awk 'NR==2')
daemonset_api=${daemonset_api:10}
clusterrolebinding_api=$(kubectl explain clusterrolebinding | awk 'NR==2')
clusterrolebinding_api=${clusterrolebinding_api:10}
clusterrole_api=$(kubectl explain clusterrole | awk 'NR==2')
clusterrole_api=${clusterrole_api:10}
serviceaccount_api=$(kubectl explain serviceaccount | awk 'NR==2')
serviceaccount_api=${serviceaccount_api:10}
deployment_api=$(kubectl explain deployment | awk 'NR==2')
deployment_api=${deployment_api:10}
read -esp "Logz.io metrics shipping token:🔒" metrics_token
printf "\n"
read -ep "Logz.io region [us]: " logzio_region
if [[ ! -z $logzio_region ]] && [[ $logzio_region != "us" ]]; then
logzio_region="-${logzio_region}"
else
logzio_region=""
fi
listener_host="listener${logzio_region}.logz.io"
cluster_name=$(kubectl config current-context)
if [[ $cluster_name == *"cluster/"* ]]; then
cluster_name=${cluster_name#*"cluster/"}
fi
read -ep "Cluster name [${cluster_name}]: " real_cluster_name
real_cluster_name=${real_cluster_name:-"${cluster_name}"}
has_eks=$(aws eks describe-cluster --name ${real_cluster_name} | grep ":eks:")
if [[ $has_eks ]]; then
shipping_protocol="https"
else
read -ep "Kubelet shipping protocol [http]: " shipping_protocol
shipping_protocol=${shipping_protocol:-"http"}
fi
shipping_port="10255"
if [[ $shipping_protocol == "https" ]]; then
shipping_port="10250"
fi
read -ep "Target namespace to deploy [kube-system]: " namespace
namespace=${namespace:-"kube-system"}
read -ep "Deploy with standard or autodiscover configuration? [standard]: " deployment_config
deployment_config=${deployment_config:-"standard"}
read -ep "Show generated yaml? (y/n) " answer
if [ "$answer" = "y" ]; then
debug="--debug"
fi
helm install ${debug} \
--namespace=${namespace} \
--set=namespace=${namespace} \
--set=shippingProtocol=${shipping_protocol} \
--set=shippingPort=${shipping_port} \
--set=apiVersions.Deployment=${deployment_api} \
--set=apiVersions.ConfigMap=${configmap_api} \
--set=apiVersions.DaemonSet=${daemonset_api} \
--set=apiVersions.ServiceAccount=${serviceaccount_api} \
--set=apiVersions.ClusterRole=${clusterrole_api} \
--set=apiVersions.ClusterRoleBinding=${clusterrolebinding_api} \
--set=configType=${deployment_config} \
--set=secrets.MetricsToken=${metrics_token} \
--set=secrets.ListenerHost=${listener_host} \
--set=secrets.ClusterName=${real_cluster_name} \
--set=secrets.KubeStatNamespace=${kube_stat_ns} \
--set=secrets.KubeStatPort=${kube_stat_port} \
--repo https://logzio.github.io/logzio-helm/metricbeat logzio-k8s-metrics logzio-k8s-metrics