Skip to content

Instantly share code, notes, and snippets.

@meetmatt
Last active July 21, 2022 01:00
Show Gist options
  • Save meetmatt/92167f8cc61e85346bbb97b4501d8d22 to your computer and use it in GitHub Desktop.
Save meetmatt/92167f8cc61e85346bbb97b4501d8d22 to your computer and use it in GitHub Desktop.
This is part 2 of 01-openstack.md gist: https://gist.github.com/yurgol/da9e7364dec04a43465e20c430fb58df

Kubernetes

Juju

Install from snap

sudo snap install juju --classic

Initialize Openstack Cloud

Cloud definition and credentials

Create cloud definition file

source /var/snap/microstack/common/etc/microstack.rc
tee openstack-cloud.yaml > /dev/null << EOL
clouds:
  openstack:
    type: openstack
    auth-types: [userpass]
    config:
      use-default-secgroup: true
      network: private
      external-network: public
      allocate-public-ip: true
      use-floating-ip: true
    endpoint: '${OS_AUTH_URL}/v3'
    regions:
      microstack: {}
EOL

Add cloud definition

juju add-cloud --client openstack openstack-cloud.yaml

Add cloud credentials

tee openstack-credentials.yaml > /dev/null << EOL
credentials:
  openstack:
    default-region: microstack
    admin:
      auth-type: userpass
      domain-name: ""
      project-domain-name: default
      tenant-id: ""
      tenant-name: admin
      user-domain-name: default
      username: admin
      password: ${OS_PASSWORD}
      version: "3"
EOL

Add credentials to juju and set as default

juju add-credential --client openstack -f openstack-credentials.yaml
juju set-default-credential openstack admin

Cloud controller

Configure simplestreams and generate the image metadata files

NB: region must be microstack:

SERIES=focal
IMAGE=$(openstack image list -f value -c ID --name ubuntu.${SERIES})
mkdir simplestreams
juju metadata generate-image \
    -d ~/simplestreams \
    -i ${IMAGE} \
    -s ${SERIES} \
    -r microstack \
    -u ${OS_AUTH_URL}/v3

Bootstrap Juju controller

Choose a large flavor: 8 VCPUs, 8GB RAM, 20GB disk

FLAVOR=8.8192.20
juju bootstrap --debug \
     --bootstrap-series=focal \
     --bootstrap-constraints allocate-public-ip=true \
     --bootstrap-constraints use-floating-ip=true \
     --bootstrap-constraints instance-type=${FLAVOR} \
     --metadata-source $HOME/simplestreams/ \
     openstack openstack

Kubernetes Charm

Model

Create model config file

tee model-config.yaml > /dev/null << EOL
allocate-public-ip: true
use-floating-ip: true
image-metadata-url: /home/ubuntu/simplestreams/images
network: private
external-network: public
EOL

Add model to Juju

juju add-model k8s openstack --config model-config.yaml

Simplestreams

Copy simplestreams data to Juju controller

tar cvzf simplestreams.tar.gz simplestreams
juju switch controller
juju scp simplestreams.tar.gz 0:
juju ssh 0 -- tar xvzf simplestreams.tar.gz

Deploy Kubernetes

Create deployment bundle

tee kubernetes-core-bundle.yaml > /dev/null << EOL
description: A minimal Kubernetes cluster, single master and single worker.
series: focal
machines:
  '0':
    constraints: cores=2 mem=4G root-disk=10G
    series: focal
  '1':
    constraints: cores=2 mem=4G root-disk=10G
    series: focal
  '2':
    constraints: cores=4 mem=4G root-disk=20G
    series: focal
  '3':
    constraints: cores=8 mem=8G root-disk=20G
    series: focal
applications:
  containerd:
    charm: cs:~containers/containerd-130
    resources: {}
  easyrsa:
    annotations:
      gui-x: '450'
      gui-y: '550'
    charm: cs:~containers/easyrsa-384
    num_units: 1
    resources:
      easyrsa: 5
    to:
    - '0'
  etcd:
    annotations:
      gui-x: '800'
      gui-y: '550'
    charm: cs:~containers/etcd-594
    num_units: 1
    resources:
      core: 0
      etcd: 3
      snapshot: 0
    to:
    - '1'
  flannel:
    annotations:
      gui-x: '450'
      gui-y: '750'
    charm: cs:~containers/flannel-558
    resources:
      flannel-amd64: 761
      flannel-arm64: 758
      flannel-s390x: 745
  kubernetes-master:
    annotations:
      gui-x: '800'
      gui-y: '850'
    charm: cs:~containers/kubernetes-master-1008
    expose: true
    num_units: 1
    options:
      channel: 1.21/stable
    resources:
      cdk-addons: 0
      core: 0
      kube-apiserver: 0
      kube-controller-manager: 0
      kube-proxy: 0
      kube-scheduler: 0
      kubectl: 0
    to:
    - '2'
  kubernetes-worker:
    annotations:
      gui-x: '100'
      gui-y: '850'
    charm: cs:~containers/kubernetes-worker-768
    expose: true
    num_units: 1
    options:
      channel: 1.21/stable
    resources:
      cni-amd64: 797
      cni-arm64: 788
      cni-s390x: 800
      core: 0
      kube-proxy: 0
      kubectl: 0
      kubelet: 0
    to:
    - '3'
relations:
- - kubernetes-master:kube-api-endpoint
  - kubernetes-worker:kube-api-endpoint
- - kubernetes-master:kube-control
  - kubernetes-worker:kube-control
- - kubernetes-master:certificates
  - easyrsa:client
- - kubernetes-master:etcd
  - etcd:db
- - kubernetes-worker:certificates
  - easyrsa:client
- - etcd:certificates
  - easyrsa:client
- - flannel:etcd
  - etcd:db
- - flannel:cni
  - kubernetes-master:cni
- - flannel:cni
  - kubernetes-worker:cni
- - containerd:containerd
  - kubernetes-worker:container-runtime
- - containerd:containerd
  - kubernetes-master:container-runtime
EOL

Create Openstack Integrator overlay configuration file

tee openstack-overlay.yaml > /dev/null << EOL
description: Charmed Kubernetes overlay to add native OpenStack support.
applications:
  openstack-integrator:
    annotations:
      gui-x: "600"
      gui-y: "300"
    charm: cs:~containers/openstack-integrator
    num_units: 1
    trust: true
relations:
  - ['openstack-integrator', 'kubernetes-master:openstack']
  - ['openstack-integrator', 'kubernetes-worker:openstack']
EOL

Deploy the charm bundle with overlay

juju deploy ./kubernetes-core-bundle.yaml --overlay openstack-overlay.yaml --trust

Watch the progress

watch -c juju status --color

Test Kubernetes

Install kubectl

sudo snap install kubectl --classic

Smoke test

Run demo

TODO

Load balancer test

Deploy second worker instance

TODO

Deploy demo services

TODO

Expose services

TODO

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