added basic setup for k8s

new-relic
Daniel Mikula 2023-05-16 10:20:39 +02:00
parent f19b1d8d5c
commit aeaa2140ab
1 changed files with 183 additions and 1 deletions

184
setup.sh
View File

@ -7,6 +7,188 @@
show_help() {
cat <<EOF
Usage: $0 <dynatrace_token>
Usage: $0 [options]
Options:
-h, --help Show help information
-e, --enironment <environment> Set environment for New Relic installation (k8s | helm | docker | linux)
-a, --account <account_number> Set account id (int)
-k, --api-key <api_key> Set API key
-r, --region <region> Set New Relic Region (EU)
-n, --cluster-name <cluster-name> Set cluster name. Required for k8s
-l, --license-key <license-key> Set license key
EOF
}
show_allowed_environments () {
cat <<EOF
Supported Environments:
- k8s
- helm not supported yet
- docker not supported yet
- linux not supported yet
EOF
}
environment = ""
account_id = ""
api_key = ""
region = ""
cluster_name = ""
license_key = ""
setup_k8s () {
curl -Ls https://download.newrelic.com/install/newrelic-cli/scripts/install.sh \
| bash && NEW_RELIC_CLI_SKIP_CORE=1 NR_CLI_CLUSTERNAME=$cluster_name \
NR_CLI_NAMESPACE=newrelic NR_CLI_PRIVILEGED=true NR_CLI_LOW_DATA_MODE=true \
NR_CLI_KSM=true NR_CLI_KUBE_EVENTS=true NR_CLI_PROMETHEUS_AGENT=true \
NR_CLI_PROMETHEUS_AGENT_LOW_DATA_MODE=true NR_CLI_CURATED=false NR_CLI_LOGGING=true \
NR_CLI_LOGGING_LOW_DATA_MODE=true NEW_RELIC_API_KEY=$api_key \
NEW_RELIC_ACCOUNT_ID=$account_id NEW_RELIC_REGION=$region\
/usr/local/bin/newrelic install -n kubernetes-open-source-integration
}
setup_docker () {
# docker run \
# -d \
# --name newrelic-infra \
# --network=host \
# --cap-add=SYS_PTRACE \
# --privileged \
# --pid=host \
# -v "/:/host:ro" \
# -v "/var/run/docker.sock:/var/run/docker.sock" \
# -e NRIA_LICENSE_KEY=$license_key \
# newrelic/infrastructure:latest
echo "Docker not supported yet"
exit 1
}
setup_linux () {
# curl -Ls https://download.newrelic.com/install/newrelic-cli/scripts/install.sh | bash && sudo NEW_RELIC_API_KEY=$api_key NEW_RELIC_ACCOUNT_ID=$account_id NEW_RELIC_REGION=$region /usr/local/bin/newrelic install -y
echo "Linux not supported yet"
exit 1
}
setup_helm () {
# function ver { printf "%03d%03d" $(echo "$1" | tr '.' ' '); } && \
# K8S_VERSION=$(kubectl version --short 2>&1 | grep 'Server Version' | awk -F' v' '{ print $2; }' | awk -F. '{ print $1"."$2; }') && \
# if [[ $(ver $K8S_VERSION) -lt $(ver "1.25") ]]; then KSM_IMAGE_VERSION="v2.6.0"; else KSM_IMAGE_VERSION="v2.7.0"; fi && \
# helm repo add newrelic https://helm-charts.newrelic.com && helm repo update && \
# kubectl create namespace newrelic ; helm upgrade --install newrelic-bundle newrelic/nri-bundle \
# --set global.licenseKey=$license_key \
# --set global.cluster=$cluster_name \
# --namespace=newrelic \
# --set newrelic-infrastructure.privileged=true \
# --set global.lowDataMode=true \
# --set kube-state-metrics.image.tag=${KSM_IMAGE_VERSION} \
# --set kube-state-metrics.enabled=true \
# --set kubeEvents.enabled=true \
# --set newrelic-prometheus-agent.enabled=true \
# --set newrelic-prometheus-agent.lowDataMode=true \
# --set newrelic-prometheus-agent.config.kubernetes.integrations_filter.enabled=false \
# --set logging.enabled=true \
# --set newrelic-logging.lowDataMode=true
echo "helm not supported yet"
exit 1
}
while [ "$#" -gt 0 ]; do
case "$1" in
-h|--help)
show_help
exit 0
;;
-e|--environment)
if [ "$2" ]; then
environment="$2"
shift 2
else
echo "Error: Missing argument for $1 option"
show_help
exit 1
fi
;;
-a|--account)
if [ "$2" ]; then
account_id="$2"
shift 2
else
if [ "$environment" == "k8s" ] || [ "$environment" == "linux"]; then
echo "Error: Missing argument for $1 option"
show_help
exit 1
else
$account_id = false
fi
fi
;;
-k|--api-key)
if [ "$2" ]; then
api_key="$2"
shift 2
else
if [ "$environment" == "k8s" ] || [ "$environment" == "linux"]; then
echo "Error: Missing argument for $1 option"
show_help
exit 1
else
$api_key = false
fi
fi
;;
-r|--region)
if [ "$2" ]; then
region="$2"
shift 2
else
if [ "$environment" == "k8s" ] || [ "$environment" == "linux"]; then
echo "Error: Missing argument for $1 option"
show_help
exit 1
else
$region = false
fi
fi
;;
-c|--cluster-name)
if [ "$2" ]; then
cluster_name="$2"
shift 2
else
if [ "$environment" == "k8s" ] || [ "$environment" == "helm"]; then
echo "Error: Missing argument for $1 option"
show_help
exit 1
else
$cluster_name = false
fi
fi
;;
-l|--license-key)
if [ "$2" ]; then
license_key="$2"
shift 2
else
if [ "$environment" == "docker" ] || [ "$environment" == "helm"]; then
echo "Error: Missing argument for $1 option"
show_help
exit 1
else
$license_key = false
fi
fi
;;
*)
echo "Error: Unrecognized option $1"
show_help
exit 1
;;
esac
done
if ["$environment" == "k8s"]; then
setup_k8s
else
echo "$environment not supported yet."
fi