@@ -22,7 +22,7 @@ function install_curl_rpm {
2222}
2323
2424function download_yamls {
25- echo " * Downloading Sysdig cluster role yaml"
25+ echo " * Downloading Sysdig cluster role yaml"
2626 curl -s -o /tmp/sysdig-agent-clusterrole.yaml https://raw.githubusercontent.com/draios/sysdig-cloud-scripts/master/agent_deploy/kubernetes/sysdig-agent-clusterrole.yaml
2727 echo " * Downloading Sysdig config map yaml"
2828 curl -s -o /tmp/sysdig-agent-configmap.yaml https://raw.githubusercontent.com/draios/sysdig-cloud-scripts/master/agent_deploy/kubernetes/sysdig-agent-configmap.yaml
@@ -38,22 +38,17 @@ function unsupported {
3838function help {
3939 echo " Usage: $( basename ${0} ) -a | --access_key <value> [-t | --tags <value>] [-c | --collector <value>] \ "
4040 echo " [-cp | --collector_port <value>] [-s | --secure <value>] [-cc | --check_certificate] \ "
41- echo " [-ac | --additional_conf <value>] [-h | --help]"
42- echo " access_key: Secret access key, as shown in Sysdig Monitor"
43- echo " tags: List of tags for this host."
44- echo " The syntax can be a comma-separated list of"
45- echo " TAG_NAME:TAG_VALUE or a single TAG_VALUE (in which case the tag"
46- echo " name \" Tag\" is implicitly assumed)."
47- echo " For example, \" role:webserver,location:europe\" , \" role:webserver\" "
48- echo " and \" webserver\" are all valid alternatives."
49- echo " collector: collector IP for Sysdig Monitor on-premises installation"
50- echo " collector_port: collector port [default 6666]"
51- echo " secure: use a secure SSL/TLS connection to send metrics to the collector"
52- echo " accepted values: true or false [default true]"
53- echo " check_certificate: disable strong SSL certificate check for Sysdig Monitor on-premises installation"
54- echo " accepted values: true or false [default true]"
55- echo " additional_conf: If provided, will be appended to agent configuration file"
56- echo " help: print this usage and exit"
41+ echo " [-ns | --namespace <value>] [-ac | --additional_conf <value>] [-h | --help]"
42+ echo " "
43+ echo " -a : secret access key, as shown in Sysdig Monitor"
44+ echo " -t : list of tags for this host (ie. \" role:webserver,location:europe\" , \" role:webserver\" or \" webserver\" )"
45+ echo " -c : collector IP for Sysdig Monitor"
46+ echo " -cp : collector port [default 6443]"
47+ echo " -s : use a secure SSL/TLS connection to send metrics to the collector (default: true)"
48+ echo " -cc : disable strong SSL certificate check (default: true)"
49+ echo " -ac : if provided, the additional configuration will be appended to agent configuration file"
50+ echo " -ns : If provided, will be the namespace used to deploy the agent. Defaults to ibm-observe"
51+ echo " -h : print this usage and exit"
5752 echo
5853 exit 1
5954}
@@ -66,9 +61,25 @@ function is_valid_value {
6661 fi
6762}
6863
64+ function create_namespace {
65+ fail=0
66+ echo " * Creating namespace: $NAMESPACE "
67+ out=$( kubectl create namespace $NAMESPACE 2>&1 ) || { fail=1 && echo " kubectl create namespace failed!" ; }
68+ if [ $fail -eq 1 ]; then
69+ if [[ " $out " =~ " AlreadyExists" ]]; then
70+ echo " $out . Continuing..."
71+ else
72+ echo " $out "
73+ exit 1
74+ fi
75+ fi
76+ }
77+
78+
6979function create_sysdig_serviceaccount {
7080 fail=0
71- out=$( kubectl create serviceaccount sysdig-agent 2>&1 ) || { fail=1 && echo " kubectl create serviceaccount failed!" ; }
81+ echo " * Creating sysdig-agent serviceaccount in namespace: $NAMESPACE "
82+ out=$( kubectl create serviceaccount sysdig-agent --namespace=$NAMESPACE 2>&1 ) || { fail=1 && echo " kubectl create serviceaccount failed!" ; }
7283 if [ $fail -eq 1 ]; then
7384 if [[ " $out " =~ " AlreadyExists" ]]; then
7485 echo " $out . Continuing..."
@@ -83,7 +94,7 @@ function install_k8s_agent {
8394 echo " * Creating sysdig-agent clusterrole and binding"
8495 kubectl apply -f /tmp/sysdig-agent-clusterrole.yaml
8596 fail=0
86- outbinding=$( kubectl create clusterrolebinding sysdig-agent --clusterrole=sysdig-agent --serviceaccount=default :sysdig-agent 2>&1 ) || { fail=1 && echo " kubectl create serviceaccount failed!" ; }
97+ outbinding=$( kubectl create clusterrolebinding sysdig-agent --clusterrole=sysdig-agent --serviceaccount=$NAMESPACE :sysdig-agent --namespace= $NAMESPACE 2>&1 ) || { fail=1 && echo " kubectl create clusterrolebinding failed!" ; }
8798 if [ $fail -eq 1 ]; then
8899 if [[ " $outbinding " =~ " AlreadyExists" ]]; then
89100 echo " $outbinding . Continuing..."
@@ -95,12 +106,12 @@ function install_k8s_agent {
95106
96107 echo " * Creating sysdig-agent secret using the ACCESS_KEY provided"
97108 fail=0
98- outsecret=$( kubectl create secret generic sysdig-agent --from-literal=access-key=$ACCESS_KEY 2>&1 ) || { fail=1 && echo " kubectl create serviceaccount failed!" ; }
109+ outsecret=$( kubectl create secret generic sysdig-agent --from-literal=access-key=$ACCESS_KEY --namespace= $NAMESPACE 2>&1 ) || { fail=1 && echo " kubectl create secret failed!" ; }
99110 if [ $fail -eq 1 ]; then
100111 if [[ " $outsecret " =~ " AlreadyExists" ]]; then
101112 echo " $outsecret . Re-creating secret..."
102- kubectl delete secrets sysdig-agent 2>&1
103- kubectl create secret generic sysdig-agent --from-literal=access-key=$ACCESS_KEY 2>&1
113+ kubectl delete secrets sysdig-agent --namespace= $NAMESPACE 2>&1
114+ kubectl create secret generic sysdig-agent --from-literal=access-key=$ACCESS_KEY --namespace= $NAMESPACE 2>&1
104115 else
105116 echo " $outsecret "
106117 exit 1
@@ -167,17 +178,21 @@ function install_k8s_agent {
167178 sed -i -e " s|# serviceAccount: sysdig-agent|serviceAccount: sysdig-agent|" /tmp/sysdig-agent-daemonset-v2.yaml
168179
169180 echo -e " new_k8s: true" >> $CONFIG_FILE
170- kubectl apply -f $CONFIG_FILE
181+ kubectl apply -f $CONFIG_FILE --namespace= $NAMESPACE
171182
172183 echo " * Deploying the sysdig agent"
173- kubectl apply -f /tmp/sysdig-agent-daemonset-v2.yaml
184+ kubectl apply -f /tmp/sysdig-agent-daemonset-v2.yaml --namespace= $NAMESPACE
174185}
175186
176187if [[ ${# } -eq 0 ]]; then
177188 echo " ERROR: Sysdig Access Key & Collector are mandatory, use -h | --help for $( basename ${0} ) Usage"
178189 exit 1
179190fi
180191
192+ # Setting the default value for NAMESPACE to be ibm-observe
193+ # Will be over-ridden if the -ns|--namespace flag is provided
194+ NAMESPACE=" ibm-observe"
195+
181196while [[ ${# } > 0 ]]
182197do
183198key=" ${1} "
@@ -237,6 +252,15 @@ case ${key} in
237252 fi
238253 shift
239254 ;;
255+ -ns|--namespace)
256+ if is_valid_value " ${2} " ; then
257+ NAMESPACE=" ${2} "
258+ else
259+ echo " ERROR: no value provided for namespace, use -h | --help for $( basename ${0} ) Usage"
260+ exit 1
261+ fi
262+ shift
263+ ;;
240264 -ac|--additional_conf)
241265 if is_valid_value " ${2} " ; then
242266 ADDITIONAL_CONF=" ${2} "
366390fi
367391
368392download_yamls
393+ create_namespace
369394create_sysdig_serviceaccount
370395install_k8s_agent
0 commit comments