From df4fe074f078cc776efc95cbb28d26ad4b5bfb19 Mon Sep 17 00:00:00 2001 From: Aleksandr Didenko Date: Mon, 27 Jun 2016 17:57:29 +0200 Subject: [PATCH] Added CCP deployment scripts --- README.md | 18 +++ Vagrantfile | 7 +- ccp/.gitignore | 2 + ccp/ccp-build.sh | 46 +++++++ ccp/ccp-deploy.sh | 23 ++++ ccp/ccp-pull.sh | 115 ++++++++++++++++++ ccp/registry_pod.yaml | 16 +++ ccp/registry_svc.yaml | 15 +++ deploy-ccp.sh | 9 ++ deploy-k8s.kargo.sh | 2 + playbooks/ccp-build.yaml | 24 ++++ playbooks/ccp-deploy.yaml | 10 ++ .../bootstrap-master.sh | 1 + .../bootstrap-node.sh | 0 .../ssh-keygen.sh | 0 15 files changed, 285 insertions(+), 3 deletions(-) create mode 100644 ccp/.gitignore create mode 100755 ccp/ccp-build.sh create mode 100755 ccp/ccp-deploy.sh create mode 100755 ccp/ccp-pull.sh create mode 100644 ccp/registry_pod.yaml create mode 100644 ccp/registry_svc.yaml create mode 100755 deploy-ccp.sh create mode 100644 playbooks/ccp-build.yaml create mode 100644 playbooks/ccp-deploy.yaml rename bootstrap-master.sh => vagrant-scripts/bootstrap-master.sh (97%) rename bootstrap-node.sh => vagrant-scripts/bootstrap-node.sh (100%) rename ssh-keygen.sh => vagrant-scripts/ssh-keygen.sh (100%) diff --git a/README.md b/README.md index 1074665fe..03c244698 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,14 @@ How-to export VAGRANT_POOL="10.100.0.0/16" ``` +* If you want to run OpenStack CCP (Containerised Control Plane) then you need to pull CCP repos and patches: + +```bash +pushd ccp +./ccp-pull.sh +popd +``` + * Prepare the virtual lab: ```bash @@ -36,3 +44,13 @@ vagrant ssh $USER-k8s-01 sudo su - ./deploy-k8s.kargo.sh ``` + +* In order to deploy OpenStack CCP login to your master node and run this: + +```bash +vagrant ssh $USER-k8s-01 +# Inside your master VM run this: +sudo su - +./deploy-ccp.sh +``` + diff --git a/Vagrantfile b/Vagrantfile index 88586710b..93471155f 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -23,7 +23,7 @@ $instance_name_prefix = "#{$user}-k8s" $box = "nrclark/xenial64-minimal-libvirt" # Create SSH keys for future lab -system 'bash ssh-keygen.sh' +system 'bash vagrant-scripts/ssh-keygen.sh' # Create nodes list for future kargo deployment nodes="" @@ -94,9 +94,10 @@ Vagrant.configure("2") do |config| config.vm.provision "custom.yaml", type: "file", source: "custom.yaml", destination: "~/custom.yaml" config.vm.provision "playbooks", type: "file", source: "playbooks", destination: "~/playbooks" config.vm.provision "nodes", type: "file", source: "nodes", destination: "~/nodes" - config.vm.provision "bootstrap", type: "shell", path: "bootstrap-master.sh" + config.vm.provision "ccp", type: "file", source: "ccp", destination: "~/ccp" + config.vm.provision "bootstrap", type: "shell", path: "vagrant-scripts/bootstrap-master.sh" else - config.vm.provision "bootstrap", type: "shell", path: "bootstrap-node.sh" + config.vm.provision "bootstrap", type: "shell", path: "vagrant-scripts/bootstrap-node.sh" end end diff --git a/ccp/.gitignore b/ccp/.gitignore new file mode 100644 index 000000000..b01055ef6 --- /dev/null +++ b/ccp/.gitignore @@ -0,0 +1,2 @@ +microservices-repos +microservices diff --git a/ccp/ccp-build.sh b/ccp/ccp-build.sh new file mode 100755 index 000000000..351ec434d --- /dev/null +++ b/ccp/ccp-build.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +set -e + +create_mcp_conf() { + echo "Create mcp config" + cat > /root/mcp.conf << EOF +[builder] +push = True +registry = "127.0.0.1:31500" + +[kubernetes] +environment = "openstack" + +[repositories] +skip_empty = True +EOF +} + +create_registry() { + if kubectl get pods | grep registry ; then + echo "Registry is already running" + else + echo "Create registry" + kubectl create -f registry_pod.yaml + kubectl create -f registry_svc.yaml + fi +} + +build_images() { + echo "Waiting for registry to start..." + while true + do + STATUS=$(kubectl get pod | awk '/registry/ {print $3}') + if [ "$STATUS" == "Running" ] + then + break + fi + sleep 1 + done + mcp-microservices --config-file /root/mcp.conf build +} + +create_mcp_conf +create_registry +build_images diff --git a/ccp/ccp-deploy.sh b/ccp/ccp-deploy.sh new file mode 100755 index 000000000..0c04368aa --- /dev/null +++ b/ccp/ccp-deploy.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +set -e + +create_network_conf() { + ( echo "network:"; i=2; for ip in `cat /root/nodes `; do echo -e " node$i:\n private:\n iface: eth2\n address: $ip"; pip=`echo $ip | perl -pe "s/(\d+).(\d+).1/\${1}.\${2}.0/g"`; echo -e " public:\n iface: eth1\n address: $pip" ; i=$(( i+=1 )) ;done ) > /root/cluster-topology.yaml +} + +assign_node_roles() { + kubectl label nodes node2 openstack-role=controller + kubectl label nodes node3 openstack-role=controller + kubectl label nodes node4 openstack-role=compute + kubectl label nodes node5 openstack-role=compute + kubectl label nodes node6 openstack-role=compute + kubectl label nodes node7 openstack-role=compute +} + +create_network_conf +assign_node_roles + +kubectl delete namespace openstack && sleep 40 +mcp-microservices --config-file=/root/mcp.conf deploy -t /root/cluster-topology.yaml + diff --git a/ccp/ccp-pull.sh b/ccp/ccp-pull.sh new file mode 100755 index 000000000..7016b80c6 --- /dev/null +++ b/ccp/ccp-pull.sh @@ -0,0 +1,115 @@ +#!/bin/bash + +set -e + +GERRIT_USER=${1:-$USER} +LOCAL_REPO="microservices-repos" +PROTO="ssh://$GERRIT_USER@" +REMOTE_REPOS=" +review.fuel-infra.org:29418/nextgen/ms-aodh +review.fuel-infra.org:29418/nextgen/ms-ceilometer +review.fuel-infra.org:29418/nextgen/ms-ceph +review.fuel-infra.org:29418/nextgen/ms-cinder +review.fuel-infra.org:29418/nextgen/ms-debian-base +review.fuel-infra.org:29418/nextgen/ms-designate +review.fuel-infra.org:29418/nextgen/ms-elasticsearch +review.fuel-infra.org:29418/nextgen/ms-ext-config +review.fuel-infra.org:29418/nextgen/ms-glance +review.fuel-infra.org:29418/nextgen/ms-grafana +review.fuel-infra.org:29418/nextgen/ms-heat +review.fuel-infra.org:29418/nextgen/ms-horizon +review.fuel-infra.org:29418/nextgen/ms-influxdb +review.fuel-infra.org:29418/nextgen/ms-ironic +review.fuel-infra.org:29418/nextgen/ms-keystone +review.fuel-infra.org:29418/nextgen/ms-kibana +review.fuel-infra.org:29418/nextgen/ms-lma +review.fuel-infra.org:29418/nextgen/ms-magnum +review.fuel-infra.org:29418/nextgen/ms-manila +review.fuel-infra.org:29418/nextgen/ms-mariadb +review.fuel-infra.org:29418/nextgen/ms-memcached +review.fuel-infra.org:29418/nextgen/ms-mistral +review.fuel-infra.org:29418/nextgen/ms-mongodb +review.fuel-infra.org:29418/nextgen/ms-murano +review.fuel-infra.org:29418/nextgen/ms-neutron +review.fuel-infra.org:29418/nextgen/ms-nova +review.fuel-infra.org:29418/nextgen/ms-openstack-base +review.fuel-infra.org:29418/nextgen/ms-openvswitch +review.fuel-infra.org:29418/nextgen/ms-rabbitmq +review.fuel-infra.org:29418/nextgen/ms-sahara +review.fuel-infra.org:29418/nextgen/ms-swift +review.fuel-infra.org:29418/nextgen/ms-tempest +review.fuel-infra.org:29418/nextgen/ms-toolbox +review.fuel-infra.org:29418/nextgen/ms-trove +review.fuel-infra.org:29418/nextgen/ms-zaqar +" + +cleanup() { + mkdir -p $LOCAL_REPO + rm -rf $LOCAL_REPO/ms-* + rm -rf microservices +} + +fetch_mcp() { + git clone "${PROTO}review.fuel-infra.org:29418/nextgen/microservices" + pushd microservices + git review -d 22325 + popd +} + +fetch_repos() { + pushd $LOCAL_REPO + for remote in $REMOTE_REPOS ; do + git clone "${PROTO}${remote}" + done + popd +} + +fetch_app_def() { + echo "Fetch app-def repos" + mariadb=21637 + keystone=21848 + memcached=21849 + rabbitmq=22053 + horizon=21850 + neutron=21886 + ovs=21951 + nova=21871 + glance=21998 + + cd $LOCAL_REPO + + cd ms-mariadb + git review -d $mariadb + cd - + cd ms-keystone + git review -d $keystone + cd - + cd ms-memcached + git review -d $memcached + cd - + cd ms-rabbitmq + git review -d $rabbitmq + cd - + cd ms-horizon + git review -d $horizon + cd - + cd ms-neutron + git review -d $neutron + cd - + cd ms-openvswitch + git review -d $ovs + cd - + cd ms-nova + git review -d $nova + cd - + cd ms-glance + git review -d $glance + cd - +} + +cleanup +fetch_mcp +fetch_repos +fetch_app_def + +echo "Microservices pull is complete" diff --git a/ccp/registry_pod.yaml b/ccp/registry_pod.yaml new file mode 100644 index 000000000..f90d9c811 --- /dev/null +++ b/ccp/registry_pod.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: Pod +metadata: + name: registry + labels: + app: registry +spec: + containers: + - name: registry + image: registry:2 + env: + imagePullPolicy: Always + ports: + - containerPort: 5000 + hostPort: 5000 + diff --git a/ccp/registry_svc.yaml b/ccp/registry_svc.yaml new file mode 100644 index 000000000..25beda960 --- /dev/null +++ b/ccp/registry_svc.yaml @@ -0,0 +1,15 @@ +kind: "Service" +apiVersion: "v1" +metadata: + name: "registry" +spec: + selector: + app: "registry" + ports: + - + protocol: "TCP" + port: 5000 + targetPort: 5000 + nodePort: 31500 + type: "NodePort" + diff --git a/deploy-ccp.sh b/deploy-ccp.sh new file mode 100755 index 000000000..db637cedc --- /dev/null +++ b/deploy-ccp.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +INVENTORY="kargo/inventory/inventory.cfg" + +echo "Createing repository and CCP images, it may take a while..." +ansible-playbook -i $INVENTORY playbooks/ccp-build.yaml + +echo "Deploying up OpenStack CCP..." +ansible-playbook -i $INVENTORY playbooks/ccp-deploy.yaml diff --git a/deploy-k8s.kargo.sh b/deploy-k8s.kargo.sh index 7a3152cc2..92801d421 100755 --- a/deploy-k8s.kargo.sh +++ b/deploy-k8s.kargo.sh @@ -23,4 +23,6 @@ deploy_res=$? if [ "$deploy_res" -eq "0" ]; then echo "Setting up kubedns..." ansible-playbook -i $INVENTORY playbooks/kubedns.yaml + echo "Setting up kubedashboard..." + ansible-playbook -i $INVENTORY playbooks/kubedashboard.yaml fi diff --git a/playbooks/ccp-build.yaml b/playbooks/ccp-build.yaml new file mode 100644 index 000000000..49b2ff214 --- /dev/null +++ b/playbooks/ccp-build.yaml @@ -0,0 +1,24 @@ +- hosts: kube-master + pre_tasks: + - name: Rsync CCP repos + synchronize: src=/root/ccp/microservices-repos/ dest=/root/microservices-repos/ + - name: Rsync MCP scripts and repo + synchronize: + src: /root/ccp/ + dest: /root/ccp/ + rsync_opts: + - "--exclude=/microservices-repos" + tasks: + - name: Install MCP + shell: "{{ item }}" + args: + chdir: /root/ccp/microservices/ + creates: /usr/local/bin/mcp-microservices + with_items: + - pip install . + - python setup.py develop + - name: Build CCP images + shell: ./ccp-build.sh + args: + chdir: /root/ccp + run_once: true diff --git a/playbooks/ccp-deploy.yaml b/playbooks/ccp-deploy.yaml new file mode 100644 index 000000000..6e7732733 --- /dev/null +++ b/playbooks/ccp-deploy.yaml @@ -0,0 +1,10 @@ +- hosts: kube-master + pre_tasks: + - name: Rsync nodes list + synchronize: src=/root/nodes dest=/root/nodes + tasks: + - name: Deploy CCP + shell: ./ccp-deploy.sh + args: + chdir: /root/ccp + run_once: true diff --git a/bootstrap-master.sh b/vagrant-scripts/bootstrap-master.sh similarity index 97% rename from bootstrap-master.sh rename to vagrant-scripts/bootstrap-master.sh index 73bcc00ac..cdee742c9 100755 --- a/bootstrap-master.sh +++ b/vagrant-scripts/bootstrap-master.sh @@ -17,6 +17,7 @@ sudo sh -c 'cd /root/kargo-cli && python setup.py install' sudo sh -c 'cp -a ~vagrant/deploy-k8s.kargo.sh /root/ && chmod 755 /root/deploy-k8s.kargo.sh' sudo cp -a ~vagrant/custom.yaml /root/custom.yaml sudo cp -a ~vagrant/playbooks /root/playbooks +sudo cp -a ~vagrant/ccp /root/ccp # SSH keys and config sudo rm -rf /root/.ssh diff --git a/bootstrap-node.sh b/vagrant-scripts/bootstrap-node.sh similarity index 100% rename from bootstrap-node.sh rename to vagrant-scripts/bootstrap-node.sh diff --git a/ssh-keygen.sh b/vagrant-scripts/ssh-keygen.sh similarity index 100% rename from ssh-keygen.sh rename to vagrant-scripts/ssh-keygen.sh