Skip to content

Commit 0397d1d

Browse files
committed
add ioc deploy and manage pages
1 parent 25d2f9a commit 0397d1d

File tree

11 files changed

+234
-51
lines changed

11 files changed

+234
-51
lines changed

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ management of IOCs.
3535
- Containers package generic IOC code and dependencies.
3636
- Kubernetes orchestrates the **Containers**.
3737
- Helm deploys IOCs to **Kubernetes**.
38-
- Repositories hold **container** images and **helm** charts
38+
- Repositories hold **Container** images and **Helm** charts
3939
- CI / CD generates the images, charts from source and delivers them
4040
to **Repositories**
4141

File renamed without changes.

docs/index.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ About the documentation
4747
tutorials/setup_k8s
4848
tutorials/useful_k8s
4949
tutorials/create_beamline
50-
tutorials/add_ioc
50+
tutorials/deploy_example
5151
tutorials/manage_iocs
5252

5353
.. toctree::
@@ -65,6 +65,7 @@ About the documentation
6565
:name: how-to
6666
:maxdepth: 1
6767

68+
how-to/add_ioc
6869
how-to/create_ioc
6970
how-to/generic_iocs
7071
how-to/debug

docs/reference/faq.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ live with K8s IOCs. Kubernetes is very well suited to running web
1111
servers so this is a natural fit.
1212

1313
There are a number of ways to support the current OPI solutions without
14-
breaking the repositories-only model. TODO: add a brief description of these.
14+
breaking the repositories-only model. The simplest approach is to extract
15+
the OPI files from the container running in Kubernetes with **kubectl cp**.
16+
Then keep a local cache and run the OPI code locally.
1517

1618

1719
Why have ioc-XXX repositories?

docs/tutorials/create_beamline.rst

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,24 +53,13 @@ In a terminal use git to clone the repository by pasting in the URL you copied
5353
in the previous step::
5454

5555

56-
[giles@gklinux2 tmp]$ git clone [email protected]:gilesknap/bl00i.git
57-
Cloning into 'bl00i'...
58-
remote: Enumerating objects: 22, done.
59-
remote: Counting objects: 100% (22/22), done.
60-
remote: Compressing objects: 100% (18/18), done.
61-
remote: Total 22 (delta 0), reused 21 (delta 0), pack-reused 0
62-
Receiving objects: 100% (22/22), 15.28 KiB | 15.28 MiB/s, done.
63-
[giles@gklinux2 tmp]$
56+
git clone [email protected]:gilesknap/bl00i.git
6457

6558
Now test that CI is working by tagging the repo and pushing it back to github::
6659

67-
68-
[giles@gklinux2 tmp]$ cd bl00i
69-
(main) [giles@gklinux2 bl00i]$ git tag 0.1
70-
(main) [giles@gklinux2 bl00i]$ git push origin 0.1
71-
Total 0 (delta 0), reused 0 (delta 0)
72-
To github.com:gilesknap/bl00i.git
73-
* [new tag] 0.1 -> 0.1
60+
cd bl00i
61+
git tag 0.1
62+
git push origin 0.1
7463

7564
This will cause github CI to generate a helm chart for the example IOC and
7665
deliver it to the account packages repository.
@@ -87,3 +76,11 @@ Go to the code pane and click on the example Package circled below to see it.
8776
.. image:: ../images/github_package.png
8877
:align: center
8978

79+
There will be one version of the package, with two tags:
80+
81+
- the tag you set on the source
82+
- and the 'latest' tag
83+
84+
85+
.. image:: ../images/github_example_package.png
86+
:align: center

docs/tutorials/deploy_example.rst

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
Deploy The Example IOC
2+
======================
3+
4+
Initial Setup
5+
-------------
6+
7+
In this tutorial step we will deploy and interact with the example ioc
8+
that came with the beamline source template we used in the previous step.
9+
10+
For this step it is assumed that you have Kubernetes set up and kubectl
11+
installed on your workstation. Also there is an epics-iocs namespace
12+
configured and your context is setup to default into that namespace. Finally
13+
helm must also be installed.
14+
15+
For instructions on how to set up Kubernetes, kubectl and helm
16+
see `setup_kubernetes`.
17+
18+
To save on typing the script kube-functions.sh provides some shell
19+
functions which are simply wrappers for kubectl and helm commands. To
20+
learn about the commands take a look at the script.
21+
22+
Source kube-functions.sh into your shell as follows. NOTE: replace
23+
gilesknap with your account::
24+
25+
export K8S_HELM_REGISTRY=ghcr.io/gilesknap
26+
wget -q https://raw.githubusercontent.com/epics-containers/k8s-epics-utils/main/epics-dev-image/home/bin/kube-functions.sh
27+
source kube-functions.sh
28+
29+
Deploy an IOC Version
30+
---------------------
31+
32+
In the previous tutorial we pushed tag 0.1 to gilesknap/bl00i and this
33+
generated a helm chart at ghcr.io/gilesknap with tags 0.1 and latest.
34+
35+
To deploy the helm chart into your cluster::
36+
37+
k8s-ioc deploy example 0.1
38+
39+
40+
Learning about Helm and Kubernetes Manifests
41+
--------------------------------------------
42+
43+
It is instructive to see what helm is doing when you execute the above
44+
command.
45+
46+
Helm uses templates to generate a set of YAML resources and applies them
47+
to the cluster using kubectl.
48+
49+
We are using a helm library defined in
50+
https://github.com/epics-containers/helm-ioc-lib. You can see the templates
51+
it is using in its templates folder.
52+
53+
The example ioc folder itself has a templates folder containing the ioc.yaml
54+
template. This includes all of the templates from helm-ioc-lib and
55+
also generates a ConfigMap resource from the files in the config folder.
56+
57+
To see the YAML that helm is generating you can use the following commands::
58+
59+
cd bl00i
60+
helm dependency update iocs/example/
61+
helm template example iocs/example
62+
63+
This is using the helm chart in your local filesystem rather than the one
64+
that we pushed to the registry so this is useful for your inner dev loop
65+
testing. You can also deploy directly from the local copy with this
66+
command::
67+
68+
helm upgrade --install example iocs/example
69+
70+
This is recommended for testing only since you won't easily be able to track
71+
versions deployed in this way.
72+
73+
Launching a GUI to interact with your IOC
74+
-----------------------------------------
75+
76+
OPI screens are outside of the scope of this project for the moment see
77+
`no_opi`.
78+
79+
However to make this example usable we have supplied some edm screens and
80+
will use a local edm container to display these. For this purpose you will
81+
require docker (or podman) installed on your workstation and your user
82+
will need to be in the docker group.
83+
84+
See here https://docs.docker.com/engine/install/ for instructions for
85+
installing docker.
86+
87+
To launch the GUI for the example IOC::
88+
89+
cd bl00i
90+
./opi/stexample-gui.sh
91+
92+
The IOC is a simulated detector with a PVA plugin. It will be possible to
93+
run a PVA viewer to see the output of this IOC.
94+
95+
The main screen of the edm OPI should look like this.
96+
97+
98+
.. image:: ../images/edm_pco.png
99+
:align: center

docs/tutorials/manage_iocs.rst

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,63 @@
1-
Deploy and Manage IOCs
2-
======================
1+
Manage IOCs
2+
===========
33

4-
Deploy an IOC Version
5-
---------------------
6-
**Todo**
4+
IOCs running in Kubernetes can be managed using the kubectl command.
75

8-
Rollback an IOC
9-
---------------
10-
(within K8s using helm and simply by doing another deploy)
11-
**Todo**
6+
The script kube-functions.sh that we used in `deploy_example` provides some
7+
shortcuts for common operations. Look inside the script to learn the
8+
underlying kubectl commands being used.
129

1310
Starting and Stopping IOCs
1411
--------------------------
15-
**Todo**
12+
13+
To stop / start the example IOC::
14+
15+
k8s-ioc stop example
16+
k8s-ioc start example
1617

1718
Monitoring and interacting with an IOC shell
1819
--------------------------------------------
19-
**Todo**
20+
21+
To attach to the ioc shell::
22+
23+
k8s-ioc attach example
24+
25+
Use the command sequence ^P^Q to detach or ^D to detach and restart the IOC.
26+
27+
To run a bash shell inside the IOC container::
28+
29+
k8s-ioc exec example
30+
31+
This is a minimal ubuntu distribution. To get access to useful utility commands
32+
use the following::
33+
34+
busybox sh
35+
busybox # shows the set of commands now available
36+
37+
Also note that the following folders may be of interest:
38+
39+
=============== ==============================================================
40+
ioc code /epics/ioc
41+
support modules /epics/support
42+
epics binaries /epics/epics-base
43+
=============== ==============================================================
44+
2045

2146
Logging
2247
-------
23-
**Todo**
48+
49+
To get the current logs for the example IOC::
50+
51+
k8s-ioc log example
52+
53+
Monitor your beamline IOCs
54+
55+
k8s-ioc monitor blxxi
56+
57+
Note that the beamline is called blxxi rather than bl00i. To change the
58+
beamline name that your IOC deploys to you would need to edit
59+
bl00i/iocs/example/values.yaml, push the changes and execute deploy again.
60+
2461

2562

2663

docs/tutorials/setup_k8s.rst

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ If you prefer to investigate other implementations there are also:
2020
- microk8s https://microk8s.io/
2121
- minikube https://minikube.sigs.k8s.io/docs/start/
2222

23+
For k3s documentation see https://k3s.io/.
24+
2325
Installation Steps
2426
------------------
2527

@@ -31,17 +33,27 @@ Execute this command on your server to set up the cluster master
3133

3234
curl -sfL https://get.k3s.io | sh -
3335

34-
Install kubectl on the workstation from which you will be managing the cluster
35-
(workstation==server if you have one machine only)::
36+
Install kubectl
37+
~~~~~~~~~~~~~~~
38+
39+
Kubectl is the command line tool for interacting with your cluster. If you
40+
have a separate workstation then you can install it there. If you only have one
41+
machine then server==workstation.
42+
43+
On the workstation install the binary::
3644

3745
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
3846
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
47+
source <(kubectl completion bash)
48+
49+
The last step adds command line completion and is worth adding to your profile.
3950

40-
Go to the server machine and copy over the kubectl configuration to your
41-
workstation::
51+
From the server machine copy over the k3s kubectl configuration::
4252

4353
sudo scp /etc/rancher/k3s/k3s.yaml <YOUR_ACCOUNT>@<YOUR_WORKSTATION>:.kube/config
44-
# edit the file .kube/config replacing 127.0.0.1 with your server IP Address
54+
55+
If you do have separate workstation then edit the file .kube/config replacing
56+
127.0.0.1 with your server's IP Address.
4557

4658

4759
Create an epics IOCs namespace and context
@@ -53,6 +65,32 @@ From the workstation execute the following::
5365
kubectl config set-context epics-iocs --namespace=epics-iocs --user=default --cluster=default
5466
kubectl config use-context epics-iocs
5567

68+
Create a service account to run the IOCs
69+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
70+
71+
Create the account::
72+
73+
kubectl apply -f - <<EOF
74+
apiVersion: v1
75+
kind: ServiceAccount
76+
metadata:
77+
name: epics-iocs-priv
78+
EOF
79+
80+
Generate a login token for the account::
81+
82+
kubectl apply -f - <<EOF
83+
apiVersion: v1
84+
kind: Secret
85+
metadata:
86+
name: epics-iocs-priv-secret
87+
annotations:
88+
kubernetes.io/service-account.name: epics-iocs-priv
89+
type: kubernetes.io/service-account-token
90+
EOF
91+
92+
.. _setup_helm:
93+
5694
Install helm
5795
~~~~~~~~~~~~
5896

@@ -67,3 +105,9 @@ Completed
67105
That's it. You now have installed the necessary software to start experimenting
68106
with IOCs on Kubernetes.
69107

108+
To remove everything you have installed above and clean up the disk space
109+
simply use this command::
110+
111+
k3s-uninstall.sh
112+
113+
If you are interested in looking at the k3s files see **/var/lib/rancher/k3s/**.

0 commit comments

Comments
 (0)