Skip to content

Instantly share code, notes, and snippets.

@ToddGreenstein
Last active March 28, 2018 09:40
Show Gist options
  • Save ToddGreenstein/346b769c1ba552dad5371f2c8c908170 to your computer and use it in GitHub Desktop.
Save ToddGreenstein/346b769c1ba552dad5371f2c8c908170 to your computer and use it in GitHub Desktop.
Quick deploy script for kubernetes if using CCM
#!/bin/bash
usage(){
echo " Usage: $0 url <clean> <tls>"
echo " url: http url to your DC/OS cluster master ip"
echo " clean: optional, will erase your DC/OS and kubectl configs and reconfigure"
echo " tls: optional, will deploy kubernetes using TLS"
echo " Minimum Config:"
echo " If using CCM the mininum configuration for the ""generic"" Kuberentes Install"
echo " 1 public slave node"
echo " 4 private slave nodes"
exit 1
}
if [ $# -eq 0 ]
then
usage
exit 1
fi
CLUSTER=$1
if [ "$2"=="clean" ]
then
echo "Clean existing CLI and kubctl configs"
rm -rf ~/.kube/config
dcos cluster remove --all
fi
echo "Attaching to $CLUSTER"
dcos cluster setup $CLUSTER --username=bootstrapuser --password=deleteme
if [ "$3"=="tls" ] || [ "$2"=="tls" ]
then
echo "Creating TLS deployment for Kubernetes"
echo "Install enterprise CLI"
dcos package install dcos-enterprise-cli --yes
echo "Sleep 5 before setting permissions..."
sleep 5
dcos security org service-accounts keypair private-key.pem public-key.pem
## dcos security org service-accounts delete kubernetes
dcos security org service-accounts create -p public-key.pem -d 'Kubernetes service account' kubernetes
## dcos security secrets delete kubernetes/sa
dcos security secrets create-sa-secret private-key.pem kubernetes kubernetes/sa
dcos security org groups add_user superusers kubernetes
echo "Sleep 5 before deploying kubernetes..."
sleep 5
echo '{
"service": {
"service_account": "kubernetes",
"service_account_secret": "kubernetes/sa"
}
}' > kubernetes_options.json
echo "Setting up Kubernetes on $CLUSTER"
dcos package install kubernetes --options=kubernetes_options.json --yes
else
echo "Setting up Kubernetes on $CLUSTER"
dcos package install kubernetes --yes
fi
echo "Set kubectl config"
dcos kubernetes kubeconfig
echo "Sleep for 90 seconds before verifying"
sleep 90
echo "Verifying Setup"
echo "kubectl get pods --all-namespaces" > output.log
kubectl get pods --all-namespaces >> output.log 2>&1
echo "----" >> output.log
echo "kubectl get services --all-namespaces" >> output.log
kubectl get services --all-namespaces >> output.log 2>&1
echo "----" >> output.log
echo "kubectl get nodes" >> output.log
kubectl get nodes >> output.log 2>&1
echo "----" >> output.log
echo "kubectl get ns" >> output.log
kubectl get ns >> output.log 2>&1
echo "----" >> output.log
echo "kubectl -n kube-system get services" >> output.log
kubectl -n kube-system get services >> output.log 2>&1
echo "----" >> output.log
echo "kubectl cluster-info dump" >> output.log
kubectl cluster-info dump>> output.log 2>&1
echo "Logged Setup to output.log"
echo "Success!"
echo "Kubernetes dashboard URL:"
echo "$CLUSTER/service/kubernetes-api-proxy/api/v1/namespaces/kube-system/services/http:kubernetes-dashboard:/proxy/"
echo "URL also copied to clipboard."
echo "$CLUSTER/service/kubernetes-api-proxy/api/v1/namespaces/kube-system/services/http:kubernetes-dashboard:/proxy/" | pbcopy
echo "Done"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment