There are 2 sample applications to start getting metrics into your cluster, postgresql-python-sample
and redis-ruby-sample
.
- AKS cluster up and running.
- Azure Redis credentials.
- Azure PostgreSQL credentials.
- Terminal connected with Kubectl to your cluster.
- Create two folders:
postgres-creds
andredis-creds
. Paste your credentials in them like the instructions suggest. - Create a kubernetes secret.
- Deploy both services:
postgresql-python-deployment.yaml
andredis-ruby-deployment.yaml
- Verify they are both up and running.
Here are the details on how to deploy each application.
To deploy the python app that consumes the PostgreSQL database you can run the following commands from the root of this directory.
Create secrets for postgreSQL credentials (remember this is not secure for prod environments):
# Create files to avoid escaping character
mkdir postgres-creds
echo -n '< REPLACE WITH POSTGRESQL USERNAME >' > postgres-creds/username-p.txt
echo -n '< REPLACE WITH POSTGRESQL PASS >' > postgres-creds/password-p.txt
echo -n '< REPLACE WITH POSTGRESQL HOSTNAME >' > postgres-creds/hostname-p.txt
kubectl create secret generic postgresql-user-pass --from-file=postgres-creds
The credentials are now stored in the cluster. You can delete them from your computer
rm -rf postgres-creds
kubectl apply -f sample-applications/postgresql-python-client/postgresql-python-deployment.yaml
See the progress of the deployment in the describe:
kubectl describe po -l app=postgresql-sample
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 74s default-scheduler Successfully assigned default/postgresql-sample-deployment-86b9d655f-mzqpj to aks-agentpool-31039371-1
Normal Pulling 72s kubelet, aks-agentpool-31039371-1 pulling image "brusmx/postgresql-python-sample:1.0"
Normal Pulled 70s kubelet, aks-agentpool-31039371-1 Successfully pulled image "brusmx/postgresql-python-sample:1.0"
Normal Created 69s kubelet, aks-agentpool-31039371-1 Created container
Normal Started 69s kubelet, aks-agentpool-31039371-1 Started container
And then after a few seconds you will see it consuming the database:
kubectl logs -l app=postgresql-sample
Obtained credentials .
Inserted 163 individuals
1516 rows. Sleeping for 300 seconds...
7 individuals deleted
1509 rows. Sleeping for 300 seconds...
To deploy the ruby app that consumes Redis you can run the following commands from the root of this directory.
Create secrets for Redis credentials:
mkdir redis-creds
# Create files to avoid escaping character
echo -n '< REPLACE WITH REDIS PASS >' > redis-creds/password-r.txt
echo -n '< REPLACE WITH POSTGRESQL HOSTNAME >' > redis-creds/hostname-r.txt
kubectl create secret generic redis-creds --from-file=redis-creds
And remove the folder from your filesystem:
rm -rf redis-creds
If you have port 6379
as default you can leave the yaml as is. If your port is different, please change it in the yaml file.
NOTE:
SSL enforced is not currently supported
kubectl apply -f sample-applications/redis-ruby-client/redis-ruby-deployment.yaml
After your pod is running, and if it's your first time running the application you will need to create the database schemas. Run the following command:
kubectl exec -it <<REDIS SAMPL POD NAME>> -- rails db:migrate
Wait for your pod to be up and running:
kubectl get pods -l app=redis-sample
---
NAME READY STATUS RESTARTS AGE
redis-sample-deployment-7f95f4b86c-ttj6b 1/1 Running 0 6m32s
You can use forward your local port 9090 to connect to that service.
kubectl port-forward redis-sample-deployment-7f95f4b86c-ttj6b 9090:3000
Visit 127.0.0.1:9090 where you willl see a list of articles. Create a few and that will upload them to Redis.