Now that we have the definitions for our application deployment, we’re going to let Ansible do the heavy lifting.
The following automation will:
Return to your code repo and create a new file at playbooks/deploy-k8s-app.yml
with the following contents:
---
- name: deploy application to k8s
hosts:
- all
module_defaults:
kubernetes.core.k8s:
kubeconfig: /tmp/kubeconfig
validate_certs: false
pre_tasks:
- name: slurp up kubeconfig
ansible.builtin.slurp:
path: /var/lib/microshift/resources/kubeadmin/kubeconfig
register: kubeconfig_raw
become: true
- name: create kubeconfig
delegate_to: localhost
ansible.builtin.copy:
content: "{{ (kubeconfig_raw['content'] | b64decode).replace('127.0.0.1', ansible_host) }}"
dest: /tmp/kubeconfig
- name: allow API access
ansible.posix.firewalld:
port: 6443/tcp
zone: public
state: enabled
immediate: true
permanent: true
become: true
tasks:
- name: make calls from localhost
delegate_to: localhost
block:
- name: create namespace
kubernetes.core.k8s:
name: process-control
kind: Namespace
state: present
- name: apply definitions
kubernetes.core.k8s:
namespace: process-control
definition: "{{ lookup('file', yaml_file) | from_yaml }}"
loop:
- files/mqtt-service.yaml
- files/mqtt-deployment.yaml
- files/simulate-deployment.yaml
- files/control-deployment.yaml
- files/ui-service.yaml
- files/ui-deployment.yaml
loop_control:
loop_var: yaml_file
This playbook handles grabbing the kubeconfig, setting the correct cluster address, then deploys our application.
Remember to commit and push your new playbook up to the git repo.
Note
Be sure to sync your project in Controller before attempting to create this job template. Make sure also to disable edge device firewall to allow calling k8s apis
In the Controller WebUI. under Resources > Templates, select Add > Add job template and enter the following information:
Parameter | Value |
---|---|
Name | Deploy K8s Application |
Inventory | Edge Systems |
Project | Device Edge Codebase |
Execution Environment | Device Edge Workshops Execution Environment |
Playbook | playbooks/deploy-k8s-app.yml |
Credentials | |
Limit |
Remember to click Save.
Now that the job template has been created, click the Launch button if you are still within the Deploy K8s Application Job Template. Otherwise, click on the rocket ship on the Templates page to launch the job template. Enter your device name when prompted on the limits page. Monitor the output for any errors or issues. However, hopefully the job executes successfully.
As a reminder, the output of jobs can be reviewed on the Jobs tab.
In lieu of completing the Bonus Steps below, a few manual steps can be taken to verify the application is up and functioning:
ansible_host
variable in Ansible Controllersudo cp /var/lib/microshift/resources/kubeadmin/kubeconfig .kubeconfig
oc
cli tool: curl https://mirror.openshift.com/pub/openshift-v4/x86_64/clients/ocp/stable/openshift-client-linux.tar.gz --output openshift-client-linux.tar.gz
oc
CLI tool: tar -xzvf openshift-client-linux.tar.gz
export KUBECONFIG=~/.kubeconfig
./oc get deployments
Assuming everything is working, 4 deployments should exist within the process-control
namespace.
In addition, the playbook above could be modified to include these steps or similar steps to get the status of the deployed application.
For some extra practice, an additional step must be taken to access the application.
/etc/hosts
), then attempt to access the application.oc
CLI utility and the port-forward
subcommand to create a tunnel to the application and test connectivity.Navigation