GithubHelp home page GithubHelp logo

jnsgruk / hello-kubecon Goto Github PK

View Code? Open in Web Editor NEW
15.0 5.0 20.0 71 KB

A Charmed Operator demonstration for Operator Day 2021, hosted by Canonical

License: Apache License 2.0

Shell 1.21% Python 98.79%
juju kubernetes demo training kubecon canonical operator-day charm charmed-operator

hello-kubecon's Introduction

Operator Day 2021 Demo Charm

Contents

Overview
Quickstart
Development Setup
Build and Deploy Locally
Testing
Get Help & Community
More Information/Related

Overview

This charm is a demonstration of a charm implemeting the sidecar pattern used during Operator Day 2021. You can grab the slides from the demo here.

The charm is written using the Charmed Operator Framework. It deploys gosherve, relying upon the charm container to populate a shared volume with a simple landing-page style website and configure the app before it is started.

Slides for the demo are available and there is a supporting Github Gist that contains copy-and- pastable content from the slide deck.

The finished charm is published on Charmhub.

The charm will:

  • Deploy a container running gosherve
  • Fetch a website from Github
  • Place the downloaded file in a storage volume
  • Expose a redirect-map config item to configure gosherve redirects
  • Expose a pull-site action to pull the latest version of the test site
  • Utilise an ingress relation using the nginx-ingress-integrator library

Each branch of this repository represents a different stage from the demonstration:

Quickstart

Assuming you already have Juju installed and bootstrapped on a cluster (if you do not, see the next section):

# Create a juju model
$ juju add-model dev
# Deploy the charm
$ juju deploy hello-kubecon
# Deploy the ingress charm
$ juju deploy traefik-k8s --trust
$ juju config traefik-k8s external_hostname=juju.local
$ juju config traefik-k8s routing_mode=subdomain
# Relate our app to the ingress
$ juju relate hello-kubecon traefik-k8s
# Wait for the deployment to complete
$ watch -n1 --color juju status --color
# Add an entry to /etc/hosts
$ echo "<traefik-k8s-address> dev-hello-kubecon.juju.local" | sudo tee -a /etc/hosts

You should be able to visit http://dev-hello-kubecon.juju.local in your browser.

Development Setup

To set up a local test environment with MicroK8s:

# Install MicroK8s
$ sudo snap install --classic microk8s
# Wait for MicroK8s to be ready
$ sudo microk8s status --wait-ready
# Enable features required by Juju controller & charm
$ sudo microk8s enable storage dns metallb
# (Optional) Alias kubectl bundled with MicroK8s package
$ sudo snap alias microk8s.kubectl kubectl
# (Optional) Add current user to 'microk8s' group
# This avoid needing to use 'sudo' with the 'microk8s' command
$ sudo usermod -aG microk8s $(whoami)
# Activate the new group (in the current shell only)
# Log out and log back in to make the change system-wide
$ newgrp microk8s
# Install Charmcraft
$ sudo snap install charmcraft
# Install juju
$ sudo snap install --classic juju
# Bootstrap the Juju controller on MicroK8s
$ juju bootstrap microk8s micro
# Add a new model to Juju
$ juju add-model dev

Build and Deploy Locally

# Clone the charm code
$ git clone https://github.com/jnsgruk/hello-kubecon && cd hello-kubecon
# Build the charm package
$ charmcraft pack
# Create a juju model
$ juju add-model dev
# Deploy!
$ juju deploy ./hello-kubecon_ubuntu-20.04-amd64.charm --resource gosherve-image=jnsgruk/gosherve:latest
# Deploy the ingress charm
$ juju deploy traefik-k8s --trust
$ juju config traefik-k8s external_hostname=juju.local
$ juju config traefik-k8s routing_mode=subdomain
# Relate our app to the ingress
$ juju relate hello-kubecon traefik-k8s
# Wait for the deployment to complete
$ watch -n1 --color juju status --color
# Add an entry to /etc/hosts
$ echo "<traefik-k8s-address> dev-hello-kubecon.juju.local" | sudo tee -a /etc/hosts

You should be able to visit http://dev-hello-kubecon.juju.local in your browser.

Testing

# Clone the charm code
$ git clone https://github.com/jnsgruk/hello-kubecon && cd hello-kubecon
# Install python3-virtualenv
$ sudo apt update && sudo apt install -y python3-virtualenv
# Create a virtualenv for the charm code
$ virtualenv venv
# Activate the venv
$ source ./venv/bin/activate
# Install dependencies
$ pip install -r requirements-dev.txt
# Run the tests
$ ./run_tests

Get Help & Community

If you get stuck deploying this charm, or would like help with charming generally, come and join the charming community!

More Information/Related

Below are some links related to this demonstration:

hello-kubecon's People

Contributors

benhoyt avatar big-c-note avatar jnsgruk avatar lferran avatar mthaddon avatar nrobinaubertin avatar weiiwang01 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

hello-kubecon's Issues

charm can be stuck in waiting state if pebble-ready fires after config-changed

Currently the charm can end up stuck in a waiting state if pebble-ready fires after config-changed. See below for details.

mthaddon@finistere:~/repos/k8s-charms/hello-kubecon/hello-kubecon$ juju debug-log --no-tail --replay| grep ' ran '
unit-hello-kubecon-0: 11:22:24 INFO juju.worker.uniter.operation ran "install" hook (via hook dispatching script: dispatch)
unit-hello-kubecon-0: 11:22:24 INFO juju.worker.uniter.operation ran "ingress-relation-created" hook (via hook dispatching script: dispatch)
unit-hello-kubecon-0: 11:22:25 INFO juju.worker.uniter.operation ran "leader-elected" hook (via hook dispatching script: dispatch)
unit-hello-kubecon-0: 11:22:25 INFO juju.worker.uniter.operation ran "webroot-storage-attached" hook (via hook dispatching script: dispatch)
unit-hello-kubecon-0: 11:22:25 INFO juju.worker.uniter.operation ran "config-changed" hook (via hook dispatching script: dispatch)
unit-hello-kubecon-0: 11:22:26 INFO juju.worker.uniter.operation ran "start" hook (via hook dispatching script: dispatch)
unit-nginx-ingress-integrator-0: 11:22:26 INFO juju.worker.uniter.operation ran "install" hook (via hook dispatching script: dispatch)
unit-hello-kubecon-0: 11:22:26 INFO juju.worker.uniter.operation ran "ingress-relation-joined" hook (via hook dispatching script: dispatch)
unit-nginx-ingress-integrator-0: 11:22:26 INFO juju.worker.uniter.operation ran "ingress-relation-created" hook (via hook dispatching script: dispatch)
unit-hello-kubecon-0: 11:22:27 INFO juju.worker.uniter.operation ran "ingress-relation-changed" hook (via hook dispatching script: dispatch)
unit-nginx-ingress-integrator-0: 11:22:27 INFO juju.worker.uniter.operation ran "leader-elected" hook (via hook dispatching script: dispatch)
unit-nginx-ingress-integrator-0: 11:22:27 INFO juju.worker.uniter.operation ran "config-changed" hook (via hook dispatching script: dispatch)
unit-hello-kubecon-0: 11:22:28 INFO juju.worker.uniter.operation ran "gosherve-pebble-ready" hook (via hook dispatching script: dispatch)
unit-nginx-ingress-integrator-0: 11:22:28 INFO juju.worker.uniter.operation ran "start" hook (via hook dispatching script: dispatch)
unit-nginx-ingress-integrator-0: 11:22:29 INFO juju.worker.uniter.operation ran "ingress-relation-changed" hook (via hook dispatching script: dispatch)
unit-hello-kubecon-0: 11:22:29 INFO juju.worker.uniter.operation ran "ingress-relation-changed" hook (via hook dispatching script: dispatch)
unit-nginx-ingress-integrator-0: 11:22:29 INFO juju.worker.uniter.operation ran "ingress-relation-joined" hook (via hook dispatching script: dispatch)
unit-nginx-ingress-integrator-0: 11:22:30 INFO juju.worker.uniter.operation ran "ingress-relation-changed" hook (via hook dispatching script: dispatch)
mthaddon@finistere:~/repos/k8s-charms/hello-kubecon/hello-kubecon$ juju status
Model     Controller          Cloud/Region        Version  SLA          Timestamp
ing-test  microk8s-localhost  microk8s/localhost  3.0.0    unsupported  11:27:14+01:00

App                       Version  Status   Scale  Charm                     Channel  Rev  Address         Exposed  Message
hello-kubecon                      waiting      1  hello-kubecon             stable    14  10.152.183.132  no       installing agent
nginx-ingress-integrator           active       1  nginx-ingress-integrator  stable    37  10.152.183.25   no       Ingress with service IP(s): 10.152.183.59

Unit                         Workload  Agent  Address       Ports  Message
hello-kubecon/0*             waiting   idle   10.1.129.141         waiting for Pebble in workload container
nginx-ingress-integrator/0*  active    idle   10.1.129.139         Ingress with service IP(s): 10.152.183.59

Deployment Documentation Nitpick

Hey Jon, quick nitpick in case it helps your new users. Thanks for the tutorial.

Under Build and Deploy Locally and Quickstart in the README:

You should be able to visit http://hellokubecon.juju in your browser.

The previous instructions deploy to http://hello-kubecon

Based on falling back to the app name due to no external hostname set and then running

# Add an entry to /etc/hosts
$ echo "127.0.1.1 hello-kubecon" | sudo tee -a /etc/hosts

(PR: #7 )

Alternatively, update external hostname to "hellokubecon.juju" and change readme to:

# Add an entry to /etc/hosts
$ echo "127.0.1.1 hellokubecon.juju" | sudo tee -a /etc/hosts

which would be more consistent with your tutorial/slides. lmk if you'd prefer that, happy to spin up a quick pr.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.