Automate Kubernetes Cluster Using Ansible

  • We need to launch a MySQL pod with the image “mysql:5.7
  • While launching mysql pod we have to provide following environment variable.
  • — env=MYSQL_USER=
  • Above env variables are used to create a database. Next, we have to launch Wordpress pod.
  • Launch Wordpress pod with appropriate image “wordpress:5.1.1-php7.3-apache”.
  • Now, expose the wordpress pod with type NodePort.
  • Connect to the Wordpress site at proper port and provide the database details and the wordpress site will be launched.
  1. Create a role. Eg: wpSQL
ansible-galaxy init wpSQL
- name: delete everything
shell: kubectl delete all --all- name: creating mysql database pod
shell: kubectl run "{{ db_pod_name }}" --image=mysql:5.7 --env=MYSQL_ROOT_PASSWORD=secretpassword --env=MYSQL_DATABASE=db1 --env=MYSQL_USER=tirth --env=MYSQL_PASSWORD=secretpassword- name: creating wordpress pod
shell: kubectl run "{{ wp_pod_name }}" --image=wordpress:5.1.1-php7.3-apache
- name: waiting for IP to comeup
seconds: 60- name: getting mysql database IP
shell: kubectl get pods -o wide
register: podsIP- name: expose wordpress pod
shell: kubectl expose pods {{ wp_pod_name }} --type=NodePort --port=80- name: get service
shell: kubectl get svc
register: service- name: printing exposed service
var: service.stdout_lines- name: printing pods IP
var: podsIP.stdout_lines
- hosts: ["tag_Name_k8s_Master"]
- name: configure wordpress and mysql database and expose wordpress
role: /root/k8s_wp_sql_play/wpSQL/





Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How to Incorporate Agile into Fixed-bid Software Consulting

Mining really long Twitter messages-threads

Why now is the time to embrace the benefits of low code platforms

Web Storage: saving different types of data

Import Local Data to Snowflake

STELLAR PLAYER — HUGE BUG (Cant uninstall).

How to run Python worker via Docker, Azure Container Instance & Azure Automation

Manage on-premise instances using AWS System Manager and Terraform

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Durgesh Kumar Patel

Durgesh Kumar Patel

More from Medium

Integrating Ansible, AWS rds, & Docker.

Knownsec Blockchain Lab | A Brief Analysis of Ether Active Data Sync

Automate Kubernetes Cluster Using Ansible

Monitoring Nginx Rate Limiting