Skip to content

Commit 7f68fc2

Browse files
author
Peter Matulis
authored
Merge pull request juju#3340 from pmatulis/improve-aws-integrator-tutorial
Improvements to Kubernetes stuff
2 parents 7404a51 + 1be832a commit 7f68fc2

File tree

5 files changed

+123
-204
lines changed

5 files changed

+123
-204
lines changed

src/en/charms-storage-k8s.md

Lines changed: 50 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ Juju storage pool called 'operator-storage' with provider type 'kubernetes' is
1515
required. We call this type of storage *operator storage*.
1616

1717
In addition, a Kubernetes charm may itself require persistent storage (e.g.
18-
the [mariadb-k8s][charm-store-staging-mariadb-k8s] charm). Its Juju storage
19-
pool also has a provider type of 'kubernetes'. We call this type of storage
20-
*charm storage* (or unit storage). As with standard charms, storage
21-
requirements are stated in the charm's `metadata.yaml` file:
18+
the [mariadb-k8s][charm-store-mariadb-k8s] charm). Its Juju storage pool also
19+
has a provider type of 'kubernetes'. We call this type of storage *charm
20+
storage* (or unit storage). As with standard charms, storage requirements are
21+
stated in the charm's `metadata.yaml` file:
2222

2323
```no-highlight
2424
storage:
@@ -125,48 +125,70 @@ created, they must also be manually removed.
125125
is 'k8s-model'. The remainder of the name, for both operator and charm
126126
storage, are fixed.
127127

128-
Tutorial [Setting up static Kubernetes storage][tutorial-k8s-static-pv] goes
129-
over this stuff in a step-by-step fashion.
130-
131128
## Storage pool creation
132129

133-
Juju storage pools are created for both operator storage and charm storage
134-
using the `create-storage-pool` command. Both are done by mapping to either a
135-
Kubernetes storage class (dynamically provisioned volumes) or to a manually
136-
defined one (statically provisioned volumes). The command's syntax is:
137-
138-
`juju create-storage-pool <pool name> kubernetes \
130+
Whether or not storage volumes are provisioned statically or dynamically Juju
131+
storage pools must be created. This is done for operator storage and, if a
132+
charm has storage requirements, for charm storage. All on a per-model basis.
133+
134+
For static storage, the number of storage pools is dependent on the storage
135+
classes listed in the PV definition files. The simplest arrangement is to have
136+
a single storage pool for each storage type and this is the approach our
137+
definition files above have taken. The two storage classes are
138+
'k8s-model-juju-operator-storage' and 'k8s-model-juju-unit-storage' .
139+
140+
Naturally, then, during the creation of a storage pool for static volumes the
141+
storage class is needed. However, Juju will automatically prepend the name of
142+
the current model (or that of the model specified via `-m`) to the referenced
143+
storage class name when it informs the cluster. Omit, therefore, the model name
144+
portion of the storage class when creating such a (static) pool.
145+
146+
The storage pool name for operator storage *must* be called 'operator-storage'
147+
while the pool name for charm storage is arbitrary. It is this charm storage
148+
pool that will be used at charm deployment time (`deploy` command). It is also
149+
this command that triggers the actual creation of the Kubernetes storage class
150+
when that storage class is used for the first time.
151+
152+
Juju storage pools are created using the standard `create-storage-pool` command
153+
and by passing values for "pool name", "storage class name", "provisioner", and
154+
optional provisioner-specific parameters. The command's syntax is:
155+
156+
`juju create-storage-pool <pool name> <storage provider> \
139157
storage-class=<storage class name> \
140158
storage-provisioner=<provisioner> \
141159
parameters.type=<paramters>`
142160

143-
For charm storage, the 'pool name' is referenced at charm deployment time by
144-
the `deploy` command. It is also this command that triggers the actual creation
145-
of the Kubernetes storage class when that storage class is referred to for the
146-
first time.
161+
In a Kubernetes context, the "storage provider" is always `kubernetes`. This
162+
provider becomes available upon the addition of a Kubernetes model.
147163

148-
The pool name for operator storage *must* be called 'operator-storage' while a
149-
pool name for charm storage is arbitrary.
164+
For static volumes, the provisioner is `kubernetes.io/no-provisioner`.
165+
166+
For dynamic volumes, the provisioner varies, depending on the underlying
167+
storage backend. Examples are given in the next two sections that follow.
150168

151169
The storage class names for both operator storage and charm storage do not need
152170
to be stated. Juju will create a name if one is not explicitly given. This is
153171
not true, however, for static volumes because a volume definition requires a
154172
storage class name.
155173

156-
The standard `storage-pools` command is used to list Juju storage pools.
157-
158174
When creating a pool, if a storage class name is provided, Juju will prefix the
159-
current model's name to that storage class name. Given a model name of
160-
'k8s-model' and a storage class name of 'juju-operator-storage', the final
161-
storage class name associated with the pool becomes
175+
current model's name to that storage class name. For instance, given a model
176+
name of 'k8s-model' and a storage class name of 'juju-operator-storage', the
177+
final storage class name associated with the pool becomes
162178
'k8s-model-juju-operator-storage'. This is really only pertinent when using
163179
static volumes as the complete storage class name must be included in the
164180
volume definition files.
165181

182+
The standard `storage-pools` command is used to list Juju storage pools.
183+
184+
!!! Note:
185+
As of time of writing, to make use of dynamically provisioned volumes a
186+
cloud-specific Juju [integrator charm][charm-store-integrator] is required.
187+
166188
### Creating operator storage pools
167189

168-
The below examples show how to create operator storage pools for various
169-
scenarios.
190+
The below examples show the syntax for creating operator storage pools for
191+
various scenarios.
170192

171193
For AWS using SSD/gp2 backed EBS volumes (dynamically provisioned):
172194

@@ -262,7 +284,6 @@ For charm storage the rules are similar:
262284
[kubernetes-hostpath]: https://kubernetes.io/docs/concepts/storage/volumes/#hostpath
263285
[kubernetes-classes]: https://kubernetes.io/docs/concepts/storage/storage-classes/
264286
[#creating-storage-pools]: #creating-storage-pools
265-
[charm-store-staging-mariadb-k8s]: https://staging.jujucharms.com/u/wallyworld/mariadb-k8s/7
266-
[tutorial-microk8s]: ./tutorial-microk8s.md
267-
[tutorial-k8s-static-pv]: ./tutorial-k8s-static-pv.md
287+
[charm-store-mariadb-k8s]: https://jujucharms.com/u/juju/mariadb-k8s/
268288
[#external-storage-and-storage-precedence-rules]: #external-storage-and-storage-precedence-rules
289+
[charm-store-integrator]: https://jujucharms.com/q/integrator

src/en/clouds-k8s.md

Lines changed: 53 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,25 @@ Title: Using Kubernetes with Juju
22
TODO: Should eventually link to k8s-charm developer documentation
33
Add architectural overview/diagram
44
Consider manually adding a cluster via `add-cloud` and `add-credential`
5-
Write tutorial on building a cluster using GCE with gcp-integrator
5+
Write tutorial on building a cluster using GCE with azure-integrator
66

77
# Using Kubernetes with Juju
88

99
Kubernetes ("k8s") provides a flexible architecture for managing containerised
1010
applications at scale. See the
1111
[Kubernetes documentation][upstream-kubernetes-docs] for more information.
1212

13-
The objective of this page is how to add an existing Kubernetes cluster to
14-
Juju. It is not about showing how to install Kubernetes *with* Juju, although
15-
we do give pointers on how to do so.
13+
The objective of this page is to give an overview of how an existing Kubernetes
14+
cluster can be integrated with Juju and what the general workflow is once
15+
that's done. Links will be provided to pages that preset more theory as well as
16+
to practical tutorials. Although this page is not about showing how to install
17+
Kubernetes itself, we do give pointers on how to do so.
1618

1719
Essentially, Juju is able to treat the added cluster as it does any other of
1820
its known clouds (i.e. create models and deploy charms). There are some
1921
differences to working with such a cloud and they are called out in the
2022
following section.
2123

22-
This document refers to page
23-
[Persistent storage and Kubernetes][charms-storage-k8s] in a few places. You
24-
may want to familiarise yourself with it now.
25-
2624
## Juju Kubernetes-specific workflow
2725

2826
The k8s-specific Juju commands are `add-k8s`, `remove-k8s`, and
@@ -49,7 +47,7 @@ list of known clouds.
4947
The `scale-application` command is used to scale a Kubernetes cluster. The
5048
`add-unit` and `remove-unit` commands do not apply to a Kubernetes model.
5149

52-
A Kubernetes cloud also requires Kubernetes-specific charms.
50+
Charms need to be written specifically for a Juju:Kubernetes context.
5351

5452
## Using Kubernetes with Juju
5553

@@ -73,25 +71,16 @@ There are many ways to obtain a Kubernetes cluster. Here is a list of
7371
suggestions:
7472

7573
- Use the '[kubernetes-core][charm-kc]' bundle, which gives a minimal
76-
two-machine cluster available in the Charm Store. Tutorial
77-
[Setting up static Kubernetes storage][tutorial-k8s-static-pv] uses this
78-
bundle.
74+
two-machine cluster available in the Charm Store.
7975
- Use the '[canonical-kubernetes][charm-cdk]' bundle. This is the Canonical
8076
Distribution of Kubernetes (CDK), which is a more sophisticated version of
8177
'kubernetes-core'.
82-
- Use the [conjure-up][upstream-conjure-up] installer. See the following
83-
resources for guidance:
84-
- The Ubuntu tutorial:
85-
[Install Kubernetes with conjure-up][ubuntu-tutorial_install-kubernetes-with-conjure-up]
86-
- The upstream getting started guide:
87-
[Spell Walkthrough][upstream-conjure-up-guide]
88-
- Use [MicroK8s][upstream-microk8s]. This gives you get a local, fully
89-
compliant Kubernetes deployment with dynamic persistent volume support. See
90-
tutorial [Using Juju with MicroK8s][tutorial-microk8s].
91-
- Use a bundle made for the major cloud vendors. There are special
92-
"integrator" charms that assist with such deployments.
93-
[Search the Charm Store][charm-store-integrator] for 'integrator'. Tutorial
94-
[Using the aws-integrator charm][tutorial-k8s-aws] demonstrates this.
78+
- Use the [conjure-up][upstream-conjure-up] installer.
79+
- Use [MicroK8s][upstream-microk8s]. This gives you a local, fully compliant
80+
Kubernetes deployment with dynamic persistent volume support.
81+
- When Kubernetes is deployed via charms, special integrator charms made for
82+
specific cloud vendors can greatly assist (e.g. storage).
83+
[Search the Charm Store][charm-store-integrator] for 'integrator'.
9584
- Use a public Kubernetes cloud vendor such as
9685
[Amazon EKS][upstream-eks-kubernetes],
9786
[Azure AKS][upstream-aks-kubernetes], and
@@ -103,96 +92,39 @@ suggestions:
10392

10493
### Add the cluster to Juju
10594

106-
We will need some information about the cluster in order to add it to Juju.
107-
This is found within the main Kubernetes configuration file.
108-
109-
!!! Note:
110-
The `conjure-up` installer adds the cluster for you. The rest of this
111-
section can be skipped if that's what you used.
112-
113-
The configuration file can be copied over from the Kubernetes master node (and
114-
saved as `~/.kube/config`). Here is one way you can do this if Juju was used to
115-
install the cluster:
116-
117-
```bash
118-
mkdir ~/.kube
119-
juju scp kubernetes-master/0:config ~/.kube/config
120-
```
95+
Information about the cluster is needed in order to add it to Juju. This is
96+
found within the main Kubernetes configuration file that can be copied over
97+
from the Kubernetes master node (and saved as `~/.kube/config`). We can then
98+
take advantage of the `add-k8s` command as it will parse the configuration file
99+
if copied to the above path. This allows us to quickly add the cluster.
121100

122-
We can now take advantage of the `add-k8s` command as it will parse the
123-
configuration file if copied to the above path. This allows us to quickly add
124-
the cluster, which we have arbitrarily called 'k8s-cloud':
125-
126-
```bash
127-
juju add-k8s k8s-cloud
128-
```
129-
130-
Confirm the successful addition of the cloud with the `clouds` command.
101+
Note that the `conjure-up` installer adds the cluster for you.
131102

132103
### Add a model
133104

134-
Add a model in the usual way. We've arbitrarily called it 'k8s-model':
135-
136-
```bash
137-
juju add-model k8s-model k8s-cloud
138-
```
139-
140-
This will cause a Kubernetes namespace in the cluster to be created that will
141-
host all of the pods and other resources for that model. The namespace is the
142-
name of the Juju model. A Kubernetes Juju model also starts off with a storage
143-
pool called 'kubernetes'. You can see this with the `storage-pools` command.
144-
145-
!!! Note:
146-
We reuse the model name of 'k8s-model' elsewhere on this page to designate,
147-
in general, a Kubernetes Juju model.
105+
Add a model in the usual way, with the `add-model` command. This will cause a
106+
Kubernetes namespace in the cluster to be created that will host all of the
107+
pods and other resources for that model. The namespace is the name of the Juju
108+
model. A Kubernetes Juju model also starts off with a storage pool called
109+
'kubernetes'.
148110

149111
### Create persistent storage
150112

151113
Create persistent static volumes for operator storage if your chosen backing
152114
cloud's storage is not supported natively by Kubernetes. You will need to do
153-
the same for charm storage if your charm has storage requirements. Here, we
154-
show examples for creating static volumes for both types:
155-
156-
```bash
157-
kubectl create -f operator-storage.yaml
158-
kubectl create -f charm-storage-vol1.yaml
159-
```
160-
161-
For in-depth coverage on this topic see tutorial
162-
[Setting up static Kubernetes storage][tutorial-k8s-static-pv].
115+
the same for charm storage if your charm has storage requirements. This is done
116+
with the Kubernetes tool `kubectl`.
163117

164118
### Create storage pools
165119

166-
Create storage pools for operator storage and, if needed, charm storage. We
167-
show examples for creating pools of both types:
168-
169-
```bash
170-
juju create-storage-pool operator-storage kubernetes \
171-
storage-class=juju-operator-storage \
172-
storage-provisioner=kubernetes.io/no-provisioner
173-
juju create-storage-pool k8s-pool kubernetes \
174-
storage-class=juju-unit-storage \
175-
storage-provisioner=kubernetes.io/no-provisioner
176-
```
177-
178-
The above tutorial also covers storage pool creation!
120+
Create storage pools for operator storage and, if needed, charm storage. This
121+
is done in the usual way, with the `create-storage-pool` command.
179122

180123
### Deploy a Kubernetes charm
181124

182-
A Kubernetes-specific charm is deployed in standard fashion. If the charm has
183-
storage requirements you will need to specify them, as you do with a normal
184-
charm. For example, here is a charm that uses the previously created charm
185-
storage called 'k8s-pool':
186-
187-
```bash
188-
juju deploy cs:~wallyworld/mariadb-k8s --storage database=k8s-pool,10M
189-
```
190-
191-
The [Using Juju storage][charms-storage-juju-deploy] page covers the above
192-
syntax.
193-
194-
If you want to deploy a Kubernetes bundle see section
195-
[Kubernetes bundles][charms-bundles-k8s].
125+
A Kubernetes-specific charm is deployed in standard fashion, with the `deploy`
126+
command. If the charm has storage requirements you will need to specify them,
127+
as you do with a normal charm.
196128

197129
#### Configuration
198130

@@ -232,6 +164,27 @@ Keys 'juju-external-hostname' and 'juju-application-path' control how the
232164
application is exposed externally using a Kubernetes Ingress Resource in
233165
conjunction with the configured ingress controller (default: nginx).
234166

167+
## Storage theory and practical guides
168+
169+
Page [Persistent storage and Kubernetes][charms-storage-k8s] explains how Juju
170+
works with Kubernetes storage.
171+
172+
The following practical guides are available:
173+
174+
- The `conjure-up` installer can be used to install Kubernetes. See the
175+
following resources for guidance:
176+
- The Ubuntu tutorial:
177+
[Install Kubernetes with conjure-up][ubuntu-tutorial_install-kubernetes-with-conjure-up]
178+
- The upstream getting started guide:
179+
[Spell Walkthrough][upstream-conjure-up-guide]
180+
- Tutorial [Setting up static Kubernetes storage][tutorial-k8s-static-pv]
181+
shows how to set up statically provisioned persistent volumes with Juju by
182+
way of the 'kubernetes-core' charm.
183+
- Tutorial [Using Juju with MicroK8s][tutorial-microk8s] provides steps for
184+
getting started with Juju and MicroK8s.
185+
- Tutorial [Using the aws-integrator charm][tutorial-k8s-aws] demonstrates
186+
deploying Kubernetes with Juju on AWS with an integrator charm.
187+
235188

236189
<!-- LINKS -->
237190

@@ -240,8 +193,6 @@ conjunction with the configured ingress controller (default: nginx).
240193
[ubuntu-tutorial_install-kubernetes-with-conjure-up]: https://tutorials.ubuntu.com/tutorial/install-kubernetes-with-conjure-up#0
241194
[charm-store-integrator]: https://jujucharms.com/q/integrator
242195
[charms-storage-k8s]: ./charms-storage-k8s.md
243-
[charms-bundles-k8s]: ./charms-bundles.md#kubernetes-bundles
244-
[charms-storage-juju-deploy]: ./charms-storage.md#juju-deploy
245196
[tutorial-microk8s]: ./tutorial-microk8s.md
246197
[tutorial-k8s-static-pv]: ./tutorial-k8s-static-pv.md
247198
[tutorial-k8s-aws]: ./tutorial-k8s-aws.md

0 commit comments

Comments
 (0)