Skip to content

Instantly share code, notes, and snippets.

@CalvinHartwell
Last active March 29, 2019 03:43
Show Gist options
  • Save CalvinHartwell/36ca61cd938a7ea9b58c0bef6f294b84 to your computer and use it in GitHub Desktop.
Save CalvinHartwell/36ca61cd938a7ea9b58c0bef6f294b84 to your computer and use it in GitHub Desktop.
juju-cdk-vsphere-deploy.sh
#!/bin/bash
# By default, juju will place across zones
# But PROD is used for production
# So we make sure everything goes into DEV
ZONE="DEV"
# bundles/cdk-charm-config.yaml can be found below in comments section.
CHARM_CONFIG="bundles/cdk-charm-config.yaml"
DATASTORE="DATASTORE"
PRI_NETWORK="VLAN DEV"
EXT_NETWORK=""
DATASTORE=""
PV_DATASTORE=""
ACTION=$1
if [ $ACTION = "preinstall" ]; then
echo "Attempting to install pre-reqs"
sudo snap install kubectl --classic
sudo snap install juju --classic
sudo apt-get install git -y
mkdir ~/.kube
elif [ $ACTION = "bootstrap" ]; then
echo "Attempting to bootstrap controller"
# bootstrap controller
juju bootstrap cdk --to zone=$ZONE --config primary-network="VLAN DEV" -vvv
elif [ $ACTION = "add-machines" ]; then
echo "Attempting to create Virtual Machines for CDK"
# set default model constraints
juju set-model-constraints mem=8G cores=2 root-disk=50G
# set model defaults
juju model-defaults primary-network="$PRI_NETWORK"
juju model-defaults primary_network="$PRI_NETWORK"
#juju model-defaults external-network="$EXT_NETWORK"
juju model-defaults datastore="$DATASTORE"
echo $PRI_NETWORK
# add etcd machines
for i in {0..2} ; do juju add-machine zone=$ZONE datastore=$DATASTORE --constraints primary-network="$PRI_NETWORK" --constraints root-disk=50G --constraints cores=4 --constraints mem=8G; done
# add kubernetes-master machines
for i in {0..1} ; do juju add-machine zone=$ZONE datastore=$DATASTORE --constraints primary-network="$PRI_NETWORK" --constraints root-disk=30G --constraints cores=4 --constraints mem=8G; done
# add kubernetes-worker machines
for i in {0..2} ; do juju add-machine zone=$ZONE datastore=$DATASTORE --constraints primary-network="$PRI_NETWORK" --constraints root-disk=30G --constraints cores=4 --constraints mem=8G; done
# add kubeapi-load-balancer machines
juju add-machine zone=$ZONE --constraints primary-network="$PRI_NETWORK" --constraints root-disk=30G --constraints cores=2 --constraints mem=4G
# add log-mon machine
juju add-machine zone=$ZONE --constraints primary-network="$PRI_NETWORK" --constraints root-disk=50G --constraints cores=4 --constraints mem=16G
# add performance mon machine
juju add-machine zone=$ZONE --constraints primary-network="$PRI_NETWORK" --constraints root-disk=50G --constraints cores=4 --constraints mem=16G
# Now check 'juju status' and when machines go to green status, migrate them to correct hypervisor.
# Also remove CD/DVD Drive and change the flag on the storage for persistant volumes.
# Make sure you set: set disk.enableUUID = true on each worker and master nodes in the cluster.
echo "Now you can migrate the machines to the correct hypervisors"
elif [ $ACTION = "deploy-charms" ]; then
echo "Attempting to deploy charms and relate them"
# because of the manual placement, we have to use deploy initially.
juju deploy ~containers/etcd-411 --to 0,1,2 -n 3 --config $CHARM_CONFIG
juju deploy ~containers/kubernetes-master-636 --to 3,4 -n 2 --config $CHARM_CONFIG
juju deploy ~containers/kubernetes-worker-502 --to 5,6,7 -n 3 --config $CHARM_CONFIG
juju deploy ~containers/kubeapi-load-balancer-613 --to 8
juju deploy ~containers/easyrsa-231 --to lxd:3
juju deploy ~containers/flannel-398
juju deploy ~containers/vsphere-integrator-2 --to 3
# deploy logging and monitoring stack
juju deploy apache2-26 --to 9 --config $CHARM_CONFIG
juju deploy elasticsearch-32 --to 9
juju deploy filebeat-20 --config $CHARM_CONFIG
juju deploy grafana-23 --to 10
juju deploy graylog-19 --to 9
juju deploy mongodb-52 --to 10 --config $CHARM_CONFIG
juju deploy prometheus2-8 --to 10
juju deploy telegraf-27
# setup the relationships
juju relate kubernetes-master:kube-api-endpoint kubeapi-load-balancer:apiserver
juju relate kubernetes-master:loadbalancer kubeapi-load-balancer:loadbalancer
juju relate kubernetes-master:kube-control kubernetes-worker:kube-control
juju relate kubernetes-master:certificates easyrsa:client
juju relate etcd:certificates easyrsa:client
juju relate kubernetes-master:etcd etcd:db
juju relate kubernetes-worker:certificates easyrsa:client
juju relate kubernetes-worker:kube-api-endpoint kubeapi-load-balancer:website
juju relate kubeapi-load-balancer:certificates easyrsa:client
juju relate flannel:etcd etcd:db
juju relate flannel:cni kubernetes-master:cni
juju relate flannel:cni kubernetes-worker:cni
juju relate apache2:reverseproxy graylog:website
juju relate graylog:elasticsearch elasticsearch:client
juju relate graylog:mongodb mongodb:database
juju relate filebeat:beats-host kubernetes-master:juju-info
juju relate filebeat:beats-host kubernetes-worker:juju-info
juju relate filebeat:logstash graylog:beats
juju relate prometheus2:grafana-source grafana:grafana-source
juju relate telegraf:prometheus-client prometheus2:target
juju relate kubernetes-master:juju-info telegraf:juju-info
juju relate kubernetes-worker:juju-info telegraf:juju-info
juju relate vsphere-integrator:clients kubernetes-master:vsphere
juju relate vsphere-integrator:clients kubernetes-worker:vsphere
# give vsphere-integrator charm permissions to interact with the vCenter
juju trust vsphere-integrator
# The solution is now deploying and can be checked using juju status
echo "The solution is now deploying, you can check the status using the command watch --color juju status"
echo "When all the services go green, it is ready to use"
elif [ $ACTION = "post-config" ]; then
echo "Attempting to Perform Post-config"
juju config vsphere-integrator datastore="$PV_DATASTORE"
juju scp kubernetes-master/0:/home/ubuntu/config ~/.kube/config
kubectl apply -f ./kubernetes-manifests/vsphere-pv-storageclass.yaml
bash ./log-mon/log-monitoring-config.sh
bash ./scripts/expose-dashboard.sh
elif [ $ACTION = "destroy-model" ]; then
echo "Attempting to Destroy CDK Model (default)"
juju destroy-model default --y
juju add-model default
elif [ $ACTION = "destroy-controller" ]; then
echo "Attempting to Destroy CDK and Controller Nodes"
juju kill-controller cdk --y
else
echo "Error: action not supported by script"
fi
~
@CalvinHartwell
Copy link
Author

CalvinHartwell commented Mar 29, 2019

bundles/cdk-charm-config.yaml

---
 kubernetes-worker:
  channel: 1.14/stable
 kubernetes-master:
  authorization-mode: "RBAC,Node"
  channel: 1.14/stable
 etcd:
  channel: 3.2/stable 
 mongodb:
  extra_daemon_options: --bind_ip_all
 apache2:
  enable_modules: headers proxy_html proxy_http 
 filebeat:
  kube_logs: true
  logpath: '/var/log/*.log /var/log/containers/*.log'

@CalvinHartwell
Copy link
Author

CalvinHartwell commented Mar 29, 2019

kubernetes-manifests/vsphere-pv-storageclass.yaml

---
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: default 
  annotations:
     storageclass.kubernetes.io/is-default-class: "true"
provisioner: kubernetes.io/vsphere-volume
parameters:
  datastore: "DEV"
  diskformat: zeroedthick
  fstype: ext3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment