diff --git a/ansibleop/ansible-k8s-modules/finish.md b/ansibleop/ansible-k8s-modules/finish.md index f0d7ec942..efbcc1f84 100644 --- a/ansibleop/ansible-k8s-modules/finish.md +++ b/ansibleop/ansible-k8s-modules/finish.md @@ -18,4 +18,4 @@ Information, check out the links below: ## Chat * Kubernetes Slack Chat (upstream): #kubernetes-operators at https://kubernetes.slack.com/ * Operator-Framework on Google Groups: https://groups.google.com/forum/#!forum/operator-framework -* OpenShift Operators Special Interest Group (SIG): https://commons.openshift.org/sig/OpenshiftOperators.html +* OpenShift Operators Special Interest Group (SIG): https://commons.openshift.org/sig/OpenshiftOperators.html \ No newline at end of file diff --git a/ansibleop/ansible-k8s-modules/index.json b/ansibleop/ansible-k8s-modules/index.json index 909e713b2..5d86d9ecc 100644 --- a/ansibleop/ansible-k8s-modules/index.json +++ b/ansibleop/ansible-k8s-modules/index.json @@ -8,13 +8,13 @@ "details": { "steps": [ { - "title": "Running the k8s Ansible modules locally", + "title": "Step 1 - Running the k8s Ansible modules locally", "text": "step1.md" }, { - "title": "Leveraging existing k8s Resource Files inside of Ansible", + "title": "Step 2 - Leveraging existing k8s Resource Files inside of Ansible", "text": "step2.md" }, { - "title": "Customizing k8s Resource files with Ansible", + "title": "Step 3 - Customizing k8s Resource files with Ansible", "text": "step3.md" }], "intro": { @@ -40,7 +40,7 @@ }, "backend": { "autoUpgrade": true, - "imageid": "openshift-4-5", + "imageid": "openshift-4-7", "port": 8443 } } diff --git a/ansibleop/ansible-k8s-modules/intro.md b/ansibleop/ansible-k8s-modules/intro.md index 15342ca1a..cd5dc05a5 100644 --- a/ansibleop/ansible-k8s-modules/intro.md +++ b/ansibleop/ansible-k8s-modules/intro.md @@ -1,3 +1,11 @@ +By the end of this scenario, you'll be able to use the Ansible k8s module for a variety of Kubernetes operations. + +In this tutorial, you will: +* Create and remove Kubernetes resources +* Reuse existing Kubernetes manifest files with Ansible + +## Getting started + Since you are interested in *using Ansible for lifecycle management of applications on Kubernetes*, it will be beneficial to learn how to use the [Ansible k8s (Kubernetes) module](https://docs.ansible.com/ansible/latest/modules/k8s_module.html#k8s-info-module). The k8s module allows you to: @@ -6,9 +14,4 @@ The k8s module allows you to: One of the biggest benefits of using Ansible in conjunction with existing Kubernetes resource files is the ability to use Ansible's built-in [Jinja templating](https://docs.ansible.com/ansible/latest/user_guide/playbooks_templating.html) engine to customize deployments by simply setting Ansible variables. ---- - -By the end of this scenario, you'll be able to use the Ansible k8s module to: - -- _Create_ and _remove_ Kubernetes resources -- _Reuse_ existing Kubernetes manifest files with Ansible +In the following sections, you will go through the above steps to interact with the Ansible Kubernetes module. Let's get started! \ No newline at end of file diff --git a/ansibleop/ansible-k8s-modules/step1.md b/ansibleop/ansible-k8s-modules/step1.md index 623f6ec47..006c4abe1 100644 --- a/ansibleop/ansible-k8s-modules/step1.md +++ b/ansibleop/ansible-k8s-modules/step1.md @@ -1,10 +1,10 @@ -For this example we will *create and delete a namespace* with the switch of an Ansible variable. +For this example we will create and delete a namespace with the switch of an Ansible variable. ---- +## Creating a new namespace through Ansible -###### **a. Modify tasks file `example-role/tasks/main.yml` to contain the Ansible shown below.** -
----
+First, modify tasks file `example-role/tasks/main.yml` to contain the Ansible shown below:
+
+```
 - name: set test namespace to {{ state }}
   k8s:
     api_version: v1
@@ -12,40 +12,33 @@ For this example we will *create and delete a namespace* with the switch of an A
     name: test
     state: "{{ state }}"
   ignore_errors: true
-
-
+``` You can easily update this file by running the following command: `wget -q https://raw.githubusercontent.com/openshift-labs/learn-katacoda/master/ansibleop/ansible-k8s-modules/assets/tasksmain1.yml -O /root/tutorial/example-role/tasks/main.yml`{{execute}} -
---- -###### **b. Modify vars file `example-role/defaults/main.yml`, setting `state: present` by default.** +Secondly, modify vars file `example-role/defaults/main.yml`, setting `state: present` by default. -
----
+```
 state: present
-
-
+``` You can easily update this file by running the following command: `wget -q https://raw.githubusercontent.com/openshift-labs/learn-katacoda/master/ansibleop/ansible-k8s-modules/assets/defaultsmain1.yml -O /root/tutorial/example-role/defaults/main.yml`{{execute}} -
---- -###### **c. Run playbook.yml, which will execute 'example-role'.** +Then, run playbook.yml, which will execute 'example-role': `ansible-playbook -i myhosts playbook.yml`{{execute}} ---- +Finally, check that the namespace `test` was created. -###### **d. Check that the namespace `test` was created.** +`oc get projects | grep test`{{execute}}. -$ `oc get projects | grep test`{{execute}} +You should see the following output: ``` NAME DISPLAY NAME STATUS test Active -``` +``` \ No newline at end of file diff --git a/ansibleop/ansible-k8s-modules/step2.md b/ansibleop/ansible-k8s-modules/step2.md index 6d09ea956..466e1448c 100644 --- a/ansibleop/ansible-k8s-modules/step2.md +++ b/ansibleop/ansible-k8s-modules/step2.md @@ -1,18 +1,12 @@ -Next, we'll use the Ansible k8s module to leverage existing Kubernetes and OpenShift Resource files. Let's take the **[nginx deployment example](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#creating-a-deployment)** - from the Kubernetes docs. +Next, we'll use the Ansible k8s module to leverage existing Kubernetes and OpenShift Resource files. Let's take the [nginx deployment example](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#creating-a-deployment) from the Kubernetes docs. - **Note**: *We've modified the resource file slightly as we will be deploying - on OpenShift.* + **Note**: We've modified the resource file slightly as we will be deploying on OpenShift. ---- +## Leverage existing K8s and OpenShift resource files - ###### **a. Copy the nginx deployment definition `nginx-deployment.yml` into `example-role/templates`, adding a .j2 extension** - - `cp nginx-deployment.yml ./example-role/templates/nginx-deployment.yml.j2`{{execute}} - - ``` -$ cat ./example-role/templates/nginx-deployment.yml.j2 +Firstly, copy the nginx deployment definition `nginx-deployment.yml` into `example-role/templates`, adding a .j2 extension. +``` kind: Deployment apiVersion: apps/v1 metadata: @@ -32,13 +26,12 @@ spec: selector: name: nginx ``` ---- +`cp nginx-deployment.yml ./example-role/templates/nginx-deployment.yml.j2`{{execute}} - ###### **b. Update tasks file `example-role/tasks/main.yml` to create the nginx deployment using the k8s module** +Next, update tasks file `example-role/tasks/main.yml` to create the nginx deployment using the k8s module -
----
+```
 - name: set test namespace to {{ state }}
   k8s:
    api_version: v1
@@ -51,23 +44,16 @@ spec:
    state: "{{ state }}"
    definition: "{{ lookup('template', 'nginx-deployment.yml.j2') }}"
    namespace: test
- 
+``` You can easily update this file by running the following command: `wget -q https://raw.githubusercontent.com/openshift-labs/learn-katacoda/master/ansibleop/ansible-k8s-modules/assets/tasksmain2.yml -O /root/tutorial/example-role/tasks/main.yml`{{execute}} ---- - -###### **c. Run the Playbook to deploy nginx onto OpenShift** - -Running the Playbook with the command below will read the `state` variable defined in `example-role/defaults/main.yml` - - `ansible-playbook -i myhosts playbook.yml`{{execute}} +After, run the Playbook to deploy nginx onto OpenShift. Running the Playbook with the command below will read the `state` variable defined in `example-role/defaults/main.yml` ---- +`ansible-playbook -i myhosts playbook.yml`{{execute}} -###### **d. Examine Playbook results** -You can see the `test` namespace created and the `nginx` deployment created in the new namespace. +Finally, examine the Playbook results. You can see the `test` namespace created and the `nginx` deployment created in the new namespace. `oc get all -n test`{{execute}} \ No newline at end of file diff --git a/ansibleop/ansible-k8s-modules/step3.md b/ansibleop/ansible-k8s-modules/step3.md index a697cabb6..299762d7a 100644 --- a/ansibleop/ansible-k8s-modules/step3.md +++ b/ansibleop/ansible-k8s-modules/step3.md @@ -1,28 +1,21 @@ Next, let's make it possible to customize the replica count for our [nginx deployment](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#creating-a-deployment) by adding an `nginx_replicas` variable to the Deployment template and filling the variable value dynamically with Ansible. ---- +## Working with replicas -###### **a. Modify vars file `example-role/defaults/main.yml`, setting `nginx_replicas: 2`** +First, modify vars file `example-role/defaults/main.yml`, setting `nginx_replicas: 2` -
----
+```
 state: present
 nginx_replicas: 2
-
-
+``` You can easily update this file by running the following command: -``` -wget -q https://raw.githubusercontent.com/openshift-labs/learn-katacoda/master/ansibleop/ansible-k8s-modules/assets/defaultsmain2.yml -O /root/tutorial/example-role/defaults/main.yml -```{{execute}} -
- ---- +`wget -q https://raw.githubusercontent.com/openshift-labs/learn-katacoda/master/ansibleop/ansible-k8s-modules/assets/defaultsmain2.yml -O /root/tutorial/example-role/defaults/main.yml`{{execute}} -###### **b. Modify nginx deployment definition `nginx-deployment.yml.j2` to read `replicas` from the `nginx_replicas` variable** +Next, modify nginx deployment definition `nginx-deployment.yml.j2` to read `replicas` from the `nginx_replicas` variable. -
+```
 kind: Deployment
 apiVersion: apps/v1
 metadata:
@@ -41,32 +34,22 @@ spec:
   replicas: {{ nginx_replicas }}
   selector:
     name: nginx
- 
+``` You can easily update this file by running the following command: -``` -wget -q https://raw.githubusercontent.com/openshift-labs/learn-katacoda/master/ansibleop/ansible-k8s-modules/assets/nginx-deployment-updated.yml.j2 -O /root/tutorial/example-role/templates/nginx-deployment.yml.j2 -```{{execute}} -
---- +`wget -q https://raw.githubusercontent.com/openshift-labs/learn-katacoda/master/ansibleop/ansible-k8s-modules/assets/nginx-deployment-updated.yml.j2 -O /root/tutorial/example-role/templates/nginx-deployment.yml.j2`{{execute}} -###### **c. Run the Playbook to change the nginx replica count** +It's time to run the Playbook to change the nginx replica count. Running the Playbook again will read the variable `nginx_replicas` and use the provided value to customize the nginx Deployment. -Running the Playbook again will read the variable `nginx_replicas` and use the provided value to customize the nginx Deployment. - - `ansible-playbook -i myhosts playbook.yml`{{execute}} +`ansible-playbook -i myhosts playbook.yml`{{execute}} --- -###### **d. Examine Playbook results** -After running the Playbook, the cluster will scale down one of the nginx pods to meet the new requested replica count of 2. +Let's examine the Playbook results! After running the Playbook, the cluster will scale down one of the nginx pods to meet the new requested replica count of 2. `oc get pods -n test`{{execute}} ---- -###### **e. Tear down the nginx deployment** - -To remove the nginx deployment, we'll override the `state` variable to contain `state=absent` using the [`-e / --extra-vars`](https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html#passing-variables-on-the-command-line) flag. +Finally, tear down the nginx deployment. To remove the nginx deployment, we'll override the `state` variable to contain `state=absent` using the [`-e / --extra-vars`](https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html#passing-variables-on-the-command-line) flag. -`ansible-playbook -i myhosts playbook.yml --extra-vars state=absent`{{execute}} +`ansible-playbook -i myhosts playbook.yml --extra-vars state=absent`{{execute}} \ No newline at end of file diff --git a/ansibleop/ansible-mcrouter-operator/finish.md b/ansibleop/ansible-mcrouter-operator/finish.md index 364ef280a..fbd1333af 100644 --- a/ansibleop/ansible-mcrouter-operator/finish.md +++ b/ansibleop/ansible-mcrouter-operator/finish.md @@ -1,4 +1,4 @@ -Thank you for taking a closer look at the *Ansible Operator*. For more +Thank you for taking a closer look at the *Mcrouter Operator*. For more Information, check out the links below: ## Git Hub diff --git a/ansibleop/ansible-mcrouter-operator/index.json b/ansibleop/ansible-mcrouter-operator/index.json index bf7c0d73e..ae6f5c24a 100644 --- a/ansibleop/ansible-mcrouter-operator/index.json +++ b/ansibleop/ansible-mcrouter-operator/index.json @@ -43,7 +43,7 @@ }, "backend": { "autoUpgrade": true, - "imageid": "openshift-4-5", + "imageid": "openshift-4-7", "port": 8443 } } diff --git a/ansibleop/ansible-mcrouter-operator/intro.md b/ansibleop/ansible-mcrouter-operator/intro.md index fc9756f7f..c51537b57 100644 --- a/ansibleop/ansible-mcrouter-operator/intro.md +++ b/ansibleop/ansible-mcrouter-operator/intro.md @@ -1,4 +1,6 @@ -The Mcrouter Operator was built with the [Ansible Operator SDK](https://github.com/operator-framework/operator-sdk/blob/master/doc/ansible/user-guide.md). It is not yet intended for production use. +In this self-paced tutorial you will learn an overview of the Mcrouter Operator, built with the [Ansible Operator SDK](https://github.com/operator-framework/operator-sdk/blob/master/doc/ansible/user-guide.md). It is not yet intended for production use. + +## Getting started [Mcrouter](https://github.com/facebook/mcrouter) is a Memcached protocol router for scaling [Memcached](http://memcached.org/) deployments. It's a core component of cache infrastructure at Facebook and Instagram where mcrouter handles almost 5 billion requests per second at peak. @@ -15,8 +17,8 @@ Mcrouter features: Mcrouter is developed and maintained by Facebook. - - At this point in our training, we should have a basic understanding of the *Operator pattern*. - - Ansible Operator is an Operator which is _powered by Ansible_. - - Custom Resource events trigger Ansible tasks as opposed to the traditional approach of handling these events with Go code. +- Ansible Operator is an Operator which is _powered by Ansible_. +- Custom Resource events trigger Ansible tasks as opposed to the traditional approach of handling these events with Go code. + + In the following sections, you will go through various stages of deployment, usage, and testing of Mcrouter. Let's get started! \ No newline at end of file diff --git a/ansibleop/ansible-operator-overview/index.json b/ansibleop/ansible-operator-overview/index.json index 1d7e6fbfd..5a6603ae4 100644 --- a/ansibleop/ansible-operator-overview/index.json +++ b/ansibleop/ansible-operator-overview/index.json @@ -52,7 +52,7 @@ }, "backend": { "autoUpgrade": true, - "imageid": "openshift-4-5", + "imageid": "openshift-4-7", "port": 8443 } } diff --git a/ansibleop/ansible-operator-overview/intro.md b/ansibleop/ansible-operator-overview/intro.md index a7136d294..7a8e1826b 100644 --- a/ansibleop/ansible-operator-overview/intro.md +++ b/ansibleop/ansible-operator-overview/intro.md @@ -1,18 +1,19 @@ -This section will give a brief overview of the *Ansible Operator* with a step-by-step example of developing an Ansible Operator using [Operator SDK](https://sdk.operatorframework.io). - -The reader is expected to have a basic understanding of the *Operator pattern*. - - Ansible Operator is an Operator which is _powered by Ansible_. - - Custom Resource events trigger Ansible tasks as opposed to the traditional approach of handling these events with Go code. - -Ansible Operator development and testing is fully supported as a first-class citizen within the Operator SDK. Operator SDK can be used to create new Operator projects, test existing Operator projects, build Operator images, and generate new Custom Resource Definitions (CRDs) for an Operator. - ---- - -By the end of this section the reader should have a basic understanding of: +In this self-paced tutorial, you will learn a brief overview of the *Ansible Operator* with a step-by-step example of developing an Ansible Operator using [Operator SDK](https://sdk.operatorframework.io). +In this tutorial, you will gain a basic understanding of: * What the Ansible Operator is * How the Ansible Operator maps Custom Resource events to Ansible code * How to pass extra variables to Ansible code via the operator * How to leverage existing roles from Ansible Galaxy * How to deploy and run the Ansible Operator in a OpenShift cluster * How to run the Ansible Operator Locally for development + +## Getting started + +The reader is expected to have a basic understanding of the *Operator pattern*. + - Ansible Operator is an Operator which is _powered by Ansible_. + - Custom Resource events trigger Ansible tasks as opposed to the traditional approach of handling these events with Go code. + +Ansible Operator development and testing is fully supported as a first-class citizen within the Operator SDK. Operator SDK can be used to create new Operator projects, test existing Operator projects, build Operator images, and generate new Custom Resource Definitions (CRDs) for an Operator. + +In the following sections, you will go through various steps to work with and leverage the Ansible Operator. Let's get started! \ No newline at end of file