You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jul 22, 2024. It is now read-only.
Copy file name to clipboardExpand all lines: workshop/Lab7/README.md
+67-26Lines changed: 67 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,9 @@
1
1
# Lab 7. Connecting to External Storage
2
-
This lab configures our nodejs guestbook Application to connect to an external database - outside of the kubernetes cluster in which the guestbook app is deployed. For this lab we will be using a managed database service offered on IBM Cloud. The advantages of using a database service is that scaling, security, etc are often taken care of for you, but you can apply this lab to any external database service such as a legacy database you might have running on premise.
2
+
This lab configures our nodejs guestbook Application to connect to an external database - outside of the kubernetes cluster in which the guestbook app is deployed. We will be using a managed database service offered on IBM Cloud. The advantages of using a database service is that scaling, security, etc are often taken care of for you, but you can apply this lab to any external database service such as a legacy database you might have running on premise.
Once completed, [skip ahead to the next section](##Next-Steps)
33
39
34
-
## Approach 2: Use the IBM Cloud Operator to provision and manage the database instance on IBM Cloud
40
+
## Approach 2: Use the IBM Cloud Operator to provision a database instance on IBM Cloud
35
41
36
42
The Operator Framework provides support for Kubernetes-native extensions to manage custom resource types through operators. Many operators are available through [operatorhub.io](https://operatorhub.io/), including the IBM Cloud operator. The IBM Cloud operator simplifies the creation of IBM Cloud services and resouces and binding credentials from these resources into a Kubernetes cluster. The instructions in this guide are adapted from the IBM Developer tutorial [Simplify the lifecycle management process for your Kubernetes apps with operators](https://developer.ibm.com/tutorials/simplify-lifecycle-management-kubernetes-openshift-ibm-cloud-operator/).
37
43
38
44
With the IBM Cloud Kubernetes Service clusters at version 1.16 and later, the Operator Framework is already installed. So all you will need to do is install the IBM Cloud Operator. New clusters created after March 1st, 2020 should all be at this level (or later).
39
45
40
-
### Installing the IBM Cloud operator
46
+
### Create an API Key for your Target Account
41
47
42
-
1. With the OLM framework and marketplace support installed, it's time to install the IBM Cloud operator. This operator will use an IBM Cloud API key to manage resources within the cluster. Begin to configure the IBM Cloud operator by logging in to the IBM Cloud account using the IBM Cloud CLI. Start by logging in to IBM Cloud
48
+
We will configure the IBM Cloud Operator to maange resources on your personal IBM Cloud Account. You will be able to create and manage a Cloudant DB lite service that only you will have access to.
43
49
44
-
```text
50
+
1. Login to your personal IBM Cloud account. Use `--sso` if using single-sign-on. Select your personal account when asked upon logging in.
51
+
52
+
```
45
53
ibmcloud login
46
54
```
47
55
48
-
1. Check your login default region to verify that there is a Cloud Foundry organization and space with this command:
56
+
```
57
+
$ ibmcloud login
58
+
API endpoint: https://cloud.ibm.com
59
+
Region: us-south
60
+
Authenticating...
61
+
OK
62
+
63
+
Select an account:
64
+
1. John H. Zaccone's Account (a21524842fc807640e69bf89c00009fc)
65
+
2. Another Account (12345)
66
+
Enter a number> 1
67
+
Targeted account John H. Zaccone's Account (a21524842fc807640e69bf89c00009fc)
68
+
69
+
70
+
API endpoint: https://cloud.ibm.com
71
+
Region: us-south
72
+
User: John.Zaccone@ibm.com
73
+
Account: John H. Zaccone's Account (a21524842fc807640e69bf89c00009fc)
74
+
Resource group: No resource group targeted, use 'ibmcloud target -g RESOURCE_GROUP'
75
+
CF API endpoint:
76
+
Org:
77
+
```
49
78
50
-
```text
51
-
ibmcloud account orgs
79
+
1. Create a service ID in IBM Cloud IAM. If possible, do not use spaces in the names for your IAM credentials. When you use the operator binding feature, any spaces are replaced with underscores.
80
+
81
+
```
82
+
ibmcloud iam service-id-create serviceid-ico
52
83
```
53
84
54
-
If there is output like:
85
+
1. Assign the service ID access to the required permissions to work with the IBM Cloud services. You will need the **Manager** role to provision a Cloudant service.
55
86
56
-
```text
57
-
Getting orgs in region 'us-south' as myemail@example.com ...
58
-
Retrieving current account...
59
-
No organizations were found.
87
+
```
88
+
ibmcloud iam service-policy-create serviceid-ico --roles Manager --resource-group-name default --region us-south
60
89
```
61
90
62
-
1. Verify that the ibmcloud CLI session is configured with a resource group for creation of the Tone Analyzer by the IBM Cloud operator. Run this command:
91
+
1. Create an API key for the service ID.
63
92
64
-
```text
65
-
ibmcloud target
93
+
```
94
+
ibmcloud iam service-api-key-create apikey-ico serviceid-ico
66
95
```
67
96
68
-
Check the output from the `ibmcloud target` command. If there is no resource group set, resulting in a message including:
97
+
1. Set the API key of the service ID as your CLI environment variable. Now, when you run the installation script, the script uses the service ID's API key. The following command is an example for macOS.
69
98
70
-
`Resource group: No resource group targeted, use 'ibmcloud target -g RESOURCE_GROUP'`
99
+
```
100
+
export IBMCLOUD_API_KEY=<apikey-ico-value>
101
+
```
71
102
72
-
then set the target resource group to the `Default` using:
103
+
1. Confirm that the API key environment variable is set in your CLI.
73
104
74
-
```text
75
-
ibmcloud target -g Default
105
+
```
106
+
echo $IBMCLOUD_API_KEY
107
+
```
108
+
109
+
### Installing the IBM Cloud operator
110
+
111
+
1. Follow the setup steps in [Lab0](../Lab0/README.md) if necessary to point your `kubectl` command-line tool to your Kubernetes cluster.
112
+
113
+
```shell
114
+
ibmcloud login
76
115
```
77
116
78
-
> some older IBM Cloud accounts may have a resource group named `default`, if you see an error using `Default`, repeat the command with `default`.
117
+
1. Target the default resource group that your service ID has privledges to.
79
118
119
+
```text
120
+
ibmcloud target -g default
121
+
```
80
122
81
123
1. The operator marketplace catalog provides a URL for the resources to install for each operator. Install the IBM Cloud Operator with the following command:
82
124
@@ -87,7 +129,7 @@ With the IBM Cloud Kubernetes Service clusters at version 1.16 and later, the Op
87
129
Check that the pod for the IBM Cloud operator is running with:
88
130
89
131
```text
90
-
kubectl get pods --namespace ibmcloud-operator-system
132
+
kubectl get pods --namespace ibm-system
91
133
```
92
134
93
135
You should see after a minute or two that the pod for the operator is running:
@@ -102,14 +144,13 @@ With the IBM Cloud Kubernetes Service clusters at version 1.16 and later, the Op
102
144
103
145
The [Operator Pattern](https://kubernetes.io/docs/concepts/extend-kubernetes/operator/) is an emerging approach to extend through automation the expertise of human operators into the cluster environment. Operators are intended to support applications and management of other resources in and related to kubernetes clusters starting at installation, but continuing to day 2 operations of monitoring, backup, fault recovery and, of course, updates.
Operators are custom code that uses the Kubernetes API (as a client) to implement a controller for a [**Custom Resource**](https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/). Unlike the controllers built into the Kubernetes control plane which run on the Kubernetes master node, operators run outside of the Kubernetes control plan as pods on the worker nodes in the cluster. You can verify that fact by the `kubectl get pods` command above, which lists the pods of the operator running on a worker node.
108
148
109
149
In addition to the IBM Cloud Operator, there are many operators that can manage resources within your cluster available from the [Operator Hub](https://operatorhub.io). The Operator Hub includes many useful operators including operators that implement database installation, monitoring tools, application development frameworks, application runtimes and more.
110
150
111
151
Your cluster now has the IBM Cloud operator installed. This operator is able to configure two custom resources in the cluster, a **Service** and a **Binding**. The **Service** defines a specific IBM Cloud service instance type to create, and the **Binding** specifies a named binding of a service instance to a secret in the cluster. For more details about the IBM Cloud operator see the [project repository](https://github.com/IBM/cloud-operators)
0 commit comments