index.md 6,1 КБ
Newer Older
danielgruesso's avatar
danielgruesso включено в состав коммита
1
2
# Runbooks

Marcel Amirault's avatar
Marcel Amirault включено в состав коммита
3
4
Runbooks are a collection of documented procedures that explain how to
carry out a particular process, be it starting, stopping, debugging,
danielgruesso's avatar
danielgruesso включено в состав коммита
5
6
or troubleshooting a particular system.

Daniel Gruesso's avatar
Daniel Gruesso включено в состав коммита
7
8
9
Using [Jupyter Notebooks](https://jupyter.org/) and the [Rubix library](https://github.com/Nurtch/rubix),
users can get started writing their own executable runbooks.

danielgruesso's avatar
danielgruesso включено в состав коммита
10
11
## Overview

Marcel Amirault's avatar
Marcel Amirault включено в состав коммита
12
13
Historically, runbooks took the form of a decision tree or a detailed
step-by-step guide depending on the condition or system.
danielgruesso's avatar
danielgruesso включено в состав коммита
14

Marcel Amirault's avatar
Marcel Amirault включено в состав коммита
15
16
Modern implementations have introduced the concept of an "executable
runbooks", where, along with a well-defined process, operators can execute
Mike Lewis's avatar
Mike Lewis включено в состав коммита
17
pre-written code blocks or database queries against a given environment.
danielgruesso's avatar
danielgruesso включено в состав коммита
18

Daniel Gruesso's avatar
Daniel Gruesso включено в состав коммита
19
## Executable Runbooks
danielgruesso's avatar
danielgruesso включено в состав коммита
20

GitLab Bot's avatar
GitLab Bot включено в состав коммита
21
> [Introduced](https://gitlab.com/gitlab-org/gitlab-foss/issues/45912) in GitLab 11.4.
danielgruesso's avatar
danielgruesso включено в состав коммита
22

Marcel Amirault's avatar
Marcel Amirault включено в состав коммита
23
24
The JupyterHub app offered via GitLab’s Kubernetes integration now ships
with Nurtch’s Rubix library, providing a simple way to create DevOps
Daniel Gruesso's avatar
Daniel Gruesso включено в состав коммита
25
26
27
runbooks. A sample runbook is provided, showcasing common operations. While Rubix makes it
simple to create common Kubernetes and AWS workflows, you can also create them manually without
Rubix.
danielgruesso's avatar
danielgruesso включено в состав коммита
28
29
30

**<i class="fa fa-youtube-play youtube" aria-hidden="true"></i>
Watch this [video](https://www.youtube.com/watch?v=Q_OqHIIUPjE)
Takuya Noguchi's avatar
Takuya Noguchi включено в состав коммита
31
for an overview of how this is accomplished in GitLab!**
danielgruesso's avatar
danielgruesso включено в состав коммита
32
33
34
35
36

## Requirements

To create an executable runbook, you will need:

Marcel Amirault's avatar
Marcel Amirault включено в состав коммита
37
1. **Kubernetes** - A Kubernetes cluster is required to deploy the rest of the applications.
Evan Read's avatar
Evan Read включено в состав коммита
38
    The simplest way to get started is to add a cluster using [GitLab's GKE integration](../index.md#add-new-gke-cluster).
Marcel Amirault's avatar
Marcel Amirault включено в состав коммита
39
40
1. **Helm Tiller** - Helm is a package manager for Kubernetes and is required to install
    all the other applications. It is installed in its own pod inside the cluster which
danielgruesso's avatar
danielgruesso включено в состав коммита
41
    can run the helm CLI in a safe environment.
Marcel Amirault's avatar
Marcel Amirault включено в состав коммита
42
1. **Ingress** - Ingress can provide load balancing, SSL termination, and name-based
danielgruesso's avatar
danielgruesso включено в состав коммита
43
    virtual hosting. It acts as a web proxy for your applications.
Marcel Amirault's avatar
Marcel Amirault включено в состав коммита
44
45
1. **JupyterHub** - [JupyterHub](https://jupyterhub.readthedocs.io/) is a multi-user service for managing notebooks across
    a team. Jupyter Notebooks provide a web-based interactive programming environment
danielgruesso's avatar
danielgruesso включено в состав коммита
46
47
48
49
    used for data analysis, visualization, and machine learning.

## Nurtch

Marcel Amirault's avatar
Marcel Amirault включено в состав коммита
50
51
52
53
Nurtch is the company behind the [Rubix library](https://github.com/Nurtch/rubix). Rubix is
an open-source python library that makes it easy to perform common DevOps tasks inside Jupyter Notebooks.
Tasks such as plotting Cloudwatch metrics and rolling your ECS/Kubernetes app are simplified
down to a couple of lines of code. See the [Nurtch Documentation](http://docs.nurtch.com/en/latest)
danielgruesso's avatar
danielgruesso включено в состав коммита
54
for more information.
danielgruesso's avatar
danielgruesso включено в состав коммита
55
56
57

## Configure an executable runbook with GitLab

Marcel Amirault's avatar
Marcel Amirault включено в состав коммита
58
Follow this step-by-step guide to configure an executable runbook in GitLab using
danielgruesso's avatar
danielgruesso включено в состав коммита
59
60
61
62
the components outlined above and the preloaded demo runbook.

### 1. Add a Kubernetes cluster

Evan Read's avatar
Evan Read включено в состав коммита
63
Follow the steps outlined in [Add new GKE cluster](../index.md#add-new-gke-cluster)
danielgruesso's avatar
danielgruesso включено в состав коммита
64
65
66
67
to add a Kubernetes cluster to your project.

### 2. Install Helm Tiller, Ingress, and JupyterHub

Mike Lewis's avatar
Mike Lewis включено в состав коммита
68
Once the cluster has been provisioned in GKE, click the **Install** button next to the **Helm Tiller** app.
danielgruesso's avatar
danielgruesso включено в состав коммита
69
70
71

![install helm](img/helm-install.png)

Mike Lewis's avatar
Mike Lewis включено в состав коммита
72
Once Tiller has been installed successfully, click the **Install** button next to the **Ingress** app.
danielgruesso's avatar
danielgruesso включено в состав коммита
73

danielgruesso's avatar
danielgruesso включено в состав коммита
74
![install ingress](img/ingress-install.png)
danielgruesso's avatar
danielgruesso включено в состав коммита
75

Mike Lewis's avatar
Mike Lewis включено в состав коммита
76
Once Ingress has been installed successfully, click the **Install** button next to the **JupyterHub** app.
danielgruesso's avatar
danielgruesso включено в состав коммита
77

danielgruesso's avatar
danielgruesso включено в состав коммита
78
![install jupyterhub](img/jupyterhub-install.png)
danielgruesso's avatar
danielgruesso включено в состав коммита
79
80
81

### 3. Login to JupyterHub and start the server

Marcel Amirault's avatar
Marcel Amirault включено в состав коммита
82
83
Once JupyterHub has been installed successfully, navigate to the displayed **Jupyter Hostname** URL and click
**Sign in with GitLab**. Authentication is automatically enabled for any user of the GitLab instance via OAuth2. This
Mike Lewis's avatar
Mike Lewis включено в состав коммита
84
will redirect to GitLab in order to authorize JupyterHub to use your GitLab account. Click **Authorize**.
danielgruesso's avatar
danielgruesso включено в состав коммита
85
86
87

![authorize jupyter](img/authorize-jupyter.png)

Marcel Amirault's avatar
Marcel Amirault включено в состав коммита
88
Once the application has been authorized you will taken back to the JupyterHub application. Click **Start My Server**.
danielgruesso's avatar
danielgruesso включено в состав коммита
89
90
91
92
The server will take a couple of seconds to start.

### 4. Configure access

Mike Lewis's avatar
Mike Lewis включено в состав коммита
93
In order for the runbook to access your GitLab project, you will need to enter a
Marcel Amirault's avatar
Marcel Amirault включено в состав коммита
94
[GitLab Access Token](../../../profile/personal_access_tokens.md)
Mike Lewis's avatar
Mike Lewis включено в состав коммита
95
as well as your Project ID in the **Setup** section of the demo runbook.
danielgruesso's avatar
danielgruesso включено в состав коммита
96

Mike Lewis's avatar
Mike Lewis включено в состав коммита
97
Double-click the **DevOps-Runbook-Demo** folder located on the left panel.
danielgruesso's avatar
danielgruesso включено в состав коммита
98
99
100

![demo runbook](img/demo-runbook.png)

Mike Lewis's avatar
Mike Lewis включено в состав коммита
101
Double-click the "Nurtch-DevOps-Demo.ipynb" runbook.
danielgruesso's avatar
danielgruesso включено в состав коммита
102
103
104

![sample runbook](img/sample-runbook.png)

Marcel Amirault's avatar
Marcel Amirault включено в состав коммита
105
The contents on the runbook will be displayed on the right side of the screen. Under the "Setup" section, you will find
danielgruesso's avatar
danielgruesso включено в состав коммита
106
107
108
entries for both your `PRIVATE_TOKEN` and your `PROJECT_ID`. Enter both these values, conserving the single quotes as follows:

```sql
Daniel Gruesso's avatar
Daniel Gruesso включено в состав коммита
109
PRIVATE_TOKEN = 'n671WNGecHugsdEDPsyo'
danielgruesso's avatar
danielgruesso включено в состав коммита
110
111
112
PROJECT_ID = '1234567'
```

Marcel Amirault's avatar
Marcel Amirault включено в состав коммита
113
Update the `VARIABLE_NAME` on the last line of this section to match the name of the variable you are using for your
danielgruesso's avatar
danielgruesso включено в состав коммита
114
115
116
117
118
119
120
121
access token. In this example our variable name is `PRIVATE_TOKEN`.

```sql
VARIABLE_VALUE = project.variables.get('PRIVATE_TOKEN').value
```

### 5. Configure an operation

Marcel Amirault's avatar
Marcel Amirault включено в состав коммита
122
123
For this example we'll use the "**Run SQL queries in Notebook**" section in the sample runbook to query
a postgres database. The first 4 lines of the section define the variables that are required for this query to function.
danielgruesso's avatar
danielgruesso включено в состав коммита
124
125
126
127
128
129
130
131
132
133
134
135

```sql
%env DB_USER={project.variables.get('DB_USER').value}
%env DB_PASSWORD={project.variables.get('DB_PASSWORD').value}
%env DB_ENDPOINT={project.variables.get('DB_ENDPOINT').value}
%env DB_NAME={project.variables.get('DB_NAME').value}
```

Create the matching variables in your project's **Settings >> CI/CD >> Variables**

![gitlab variables](img/gitlab-variables.png)

Marcel Amirault's avatar
Marcel Amirault включено в состав коммита
136
Back in Jupyter, click the "Run SQL queries in Notebook" heading and the click *Run*. The results will be
danielgruesso's avatar
danielgruesso включено в состав коммита
137
138
139
140
displayed in-line as follows:

![postgres query](img/postgres-query.png)

Marcel Amirault's avatar
Marcel Amirault включено в состав коммита
141
142
You can try other operations such as running shell scripts or interacting with a Kubernetes cluster. Visit the
[Nurtch Documentation](http://docs.nurtch.com/) for more information.