This repository contains a bash script that automates the process of creating a Kubernetes cluster using kops
and deploying a LAMP (Linux, Apache, MySQL, PHP) stack application.
Before running the script, make sure you have the following tools installed and configured:
Additionally, ensure you have:
- An AWS account with appropriate permissions.
- A domain managed in Route 53 or a subdomain.
The script performs the following steps:
- Checks for prerequisites.
- Creates an S3 bucket for kops state storage.
- Creates a Kubernetes cluster with
kops
. - Creates a namespace.
- Deploys a MySQL database.
- Deploys a PHP application using Apache.
- Exposes the PHP application.
- Verifies the deployments.
- Optionally, cleans up resources.
-
Clone the repository or save the script to a file, e.g.,
kops_deploy_lamp.sh
. -
Make the script executable:
chmod +x kops_deploy_lamp.sh
-
Update the script variables at the top of the script with your own values, such as
CLUSTER_NAME
,STATE_BUCKET
,ZONE
, etc. -
Run the script:
./kops_deploy_lamp.sh
-
To clean up the cluster after verification, uncomment the
delete_cluster
function call at the end of the script.
CLUSTER_NAME
: The name of the Kubernetes cluster.STATE_BUCKET
: The name of the S3 bucket for storing kops state files.KOPS_STATE_STORE
: The S3 bucket URL for kops state storage.NODE_COUNT
: The number of nodes in the cluster.NODE_SIZE
: The instance type for the nodes.MASTER_SIZE
: The instance type for the master node.ZONE
: The AWS availability zone.NAMESPACE
: The namespace for deploying the applications.
After running the script, the MySQL database and the PHP application will be deployed, and the PHP application will be exposed via a LoadBalancer. You can verify the deployment by checking the status of the pods and services:
kubectl get pods -n <namespace>
kubectl get services -n <namespace>