diff --git a/cluster/juju/bundles/local.yaml b/cluster/juju/bundles/local.yaml index 1ba1b38f23..8b19f0c3ca 100644 --- a/cluster/juju/bundles/local.yaml +++ b/cluster/juju/bundles/local.yaml @@ -18,7 +18,8 @@ kubernetes-local: "gui-x": "0" "gui-y": "0" flannel-docker: - charm: cs:trusty/flannel-docker + charm: flannel-docker + branch: https://github.com/chuckbutler/flannel-docker-charm.git annotations: "gui-x": "0" "gui-y": "300" @@ -35,8 +36,12 @@ kubernetes-local: relations: - - "flannel-docker:network" - "docker:network" + - - "flannel-docker:network" + - "kubernetes-master:network" - - "flannel-docker:docker-host" - "docker:juju-info" + - - "flannel-docker:docker-host" + - "kubernetes-master:juju-info" - - "flannel-docker:db" - "etcd:client" - - "kubernetes:docker-host" diff --git a/cluster/juju/charms/trusty/kubernetes-master/actions.yaml b/cluster/juju/charms/trusty/kubernetes-master/actions.yaml new file mode 100644 index 0000000000..6c71f7afe0 --- /dev/null +++ b/cluster/juju/charms/trusty/kubernetes-master/actions.yaml @@ -0,0 +1,3 @@ +petstore: + description: Deploy the Kubernetes Petstore app + diff --git a/cluster/juju/charms/trusty/kubernetes-master/actions/lib/parse_get_pods b/cluster/juju/charms/trusty/kubernetes-master/actions/lib/parse_get_pods new file mode 100755 index 0000000000..889fe2d7ec --- /dev/null +++ b/cluster/juju/charms/trusty/kubernetes-master/actions/lib/parse_get_pods @@ -0,0 +1,17 @@ +#!/usr/bin/env python + +import json +import sys + + +def parse_pod_output(): + out = sys.stdin.readlines() + foo = json.loads(' '.join(out)) + for item in foo['items']: + name_slugs = set(item['metadata']['name'].split('-')) + if 'fectrl' in name_slugs: + if item['status']['phase'] == "Running": + print item['status']['podIP'] + +if __name__ == "__main__": + parse_pod_output() diff --git a/cluster/juju/charms/trusty/kubernetes-master/actions/petstore b/cluster/juju/charms/trusty/kubernetes-master/actions/petstore new file mode 100755 index 0000000000..c309d89b57 --- /dev/null +++ b/cluster/juju/charms/trusty/kubernetes-master/actions/petstore @@ -0,0 +1,40 @@ +#!/bin/bash + +set -eux + +export KUBE_MASTER_IP=0.0.0.0 +export KUBERNETES_MASTER=http://$KUBE_MASTER_IP + +# The test is a bit spammy with files, head over to /tmp to discard when done +cd /tmp + +# Need to update the script with the proposed IP of the web-head pod +# Currently its set to 10.1.4.89 + +sed -i 's/pass_http=0/exit 0/' /opt/kubernetes/examples/k8petstore/k8petstore.sh +/opt/kubernetes/examples/k8petstore/k8petstore.sh + +# Loop until the daemon has come online +counter=0 +KUBE_POD_STATUS="Pending" +while [ "$KUBE_POD_STATUS" == "Pending" ] +do + if [[ counter -eq 200 ]]; then + echo "Pod failed to come online. Timeout reached" + exit 1 + fi + CUR_STATUS=$(kubectl get pods -o json | $CHARM_DIR/actions/lib/parse_get_pods) + if [ ! -z "$CUR_STATUS" ]; then + KUBE_POD_STATUS=$CUR_STATUS + fi + sleep 1 + counter+=1 +done + +sed -i 's/exit 0/pass_http=0/' /opt/kubernetes/examples/k8petstore/k8petstore.sh +sed -i "s/PUBLIC_IP=\"10.1.4.89\"/PUBLIC_IP=\"$KUBE_POD_STATUS\"/" /opt/kubernetes/examples/k8petstore/k8petstore.sh +/opt/kubernetes/examples/k8petstore/k8petstore.sh + +# Return execution to the CHARM_DIR for further actions +cd $CHARM_DIR + diff --git a/cluster/juju/charms/trusty/kubernetes-master/hooks/hooks.py b/cluster/juju/charms/trusty/kubernetes-master/hooks/hooks.py index 238f451216..1acbae9835 100755 --- a/cluster/juju/charms/trusty/kubernetes-master/hooks/hooks.py +++ b/cluster/juju/charms/trusty/kubernetes-master/hooks/hooks.py @@ -141,6 +141,11 @@ def relation_changed(): # Send api endpoint to minions notify_minions() +@hooks.hook('network-relation-changed') +def network_relation_changed(): + relation_id = hookenv.relation_id() + hookenv.relation_set(relation_id, ignore_errors=True) + def notify_minions(): print("Notify minions.") diff --git a/cluster/juju/charms/trusty/kubernetes-master/metadata.yaml b/cluster/juju/charms/trusty/kubernetes-master/metadata.yaml index 27eb421e49..1bee6e44ed 100644 --- a/cluster/juju/charms/trusty/kubernetes-master/metadata.yaml +++ b/cluster/juju/charms/trusty/kubernetes-master/metadata.yaml @@ -17,3 +17,5 @@ provides: requires: etcd: interface: etcd + network: + interface: overlay-network diff --git a/cluster/juju/util.sh b/cluster/juju/util.sh index 77830853fa..009dcd0c8b 100755 --- a/cluster/juju/util.sh +++ b/cluster/juju/util.sh @@ -58,7 +58,7 @@ function kube-down() { function detect-master() { local kubestatus # Capturing a newline, and my awk-fu was weak - pipe through tr -d - kubestatus=$(juju status --format=oneline kubernetes-master | awk '{print $3}' | tr -d "\n") + kubestatus=$(juju status --format=oneline kubernetes-master | grep kubernetes-master/0 | awk '{print $3}' | tr -d "\n") export KUBE_MASTER_IP=${kubestatus} export KUBE_MASTER=${KUBE_MASTER_IP} export KUBERNETES_MASTER=http://${KUBE_MASTER}:8080 diff --git a/cluster/kubectl.sh b/cluster/kubectl.sh index 10ccd4f83f..df35ab1620 100755 --- a/cluster/kubectl.sh +++ b/cluster/kubectl.sh @@ -105,7 +105,7 @@ if [[ "$KUBERNETES_PROVIDER" == "gke" ]]; then config=( "--context=gke_${PROJECT}_${ZONE}_${CLUSTER_NAME}" ) -elif [[ "$KUBERNETES_PROVIDER" == "ubuntu" ]]; then +elif [[ "$KUBERNETES_PROVIDER" == "ubuntu" || "$KUBERNETES_PROVIDER" == "juju" ]]; then detect-master > /dev/null config=( "--server=http://${KUBE_MASTER_IP}:8080" diff --git a/docs/getting-started-guides/juju.md b/docs/getting-started-guides/juju.md index 7884902fcd..c646daa96c 100644 --- a/docs/getting-started-guides/juju.md +++ b/docs/getting-started-guides/juju.md @@ -5,7 +5,6 @@ wide number of clouds, supporting service orchestration once the bundle of services has been deployed. - ### Prerequisites > Note: If you're running kube-up, on ubuntu - all of the dependencies @@ -165,8 +164,23 @@ We can add minion units like so: juju add-unit docker # creates unit docker/2, kubernetes/2, docker-flannel/2 +## Launch the "petstore" example app + +The petstore example is available as a +[juju action](https://jujucharms.com/docs/devel/actions). + + juju action do kubernetes-master/0 + + +Note: this example includes curl statements to exercise the app. + + ## Tear down cluster + ./kube-down.sh + +or + juju destroy-environment --force `juju env`