Deploying to Kubernetes with ansible-container

Let's learn how to run the image we just built with ansible-container.

First of all, we need the image itself, and you should have it since this is the output of the previous section!

We will assume that you have access to either a Kubernetes or OpenShift cluster for testing. Setting these up is out the scope of this book, so you might want to look at a distribution such as Minikube or Minishift, both of which are designed to be quick and easy to set up so that you can start learning these technologies rapidly. We also need to have the kubectl client or the oc client, based on the fact that we have deployed Kubernetes or OpenShift, properly configured. Let's get started:

  1. To deploy your application to your cluster, you need to change the container.yml file so that you can add some additional information. More specifically, we will need to add a section called settings and a section called k8s_namespace to declare our deployment settings. This section will look something like this:
k8s_namespace:
name: http-server
description: An HTTP server
display_name: HTTP server
  1. Now that we have added the necessary information about the Kubernetes deployment, we can proceed with the deployment:
$ ansible-container --engine kubernetes deploy

As soon as Ansible has completed its execution, you will be able to find the http-server deployment on your Kubernetes cluster.

What happens behind the scenes is that Ansible has a set of modules (whose name usually starts with k8s) that are used to drive a Kubernetes cluster, and it uses them to deploy the application automatically.

Based on the image that we built in the previous section and the additional information we added at the beginning of this section, Ansible is able to populate a deployment template and then deploy it using the k8s module.

Now that you have learned how to deploy your container on a Kubernetes cluster, you'll learn how to interact with the Kubernetes cluster with Ansible.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset