aws-containers / eks-app-mesh-polyglot-demo

End to end deployment and observability of polyglot microservices in Amazon EKS using AWS App Mesh, AWS Fargate, Amazon Cloudwatch Container Insights, and AWS X-Ray
MIT No Attribution
64 stars 636 forks source link

fixed hostname (command not found) failure in init-mysql stateful sets #22

Closed gr8sk8s closed 2 years ago

gr8sk8s commented 2 years ago

Our workshop class (everyone) ran into the following issue during Stateful sets deployment, which was a showstopper:

The Issue: mysql-0 failed to deploy due to an issue in init-mysql, as seen in the logs for this init container :

$ kubectl -n workshop logs mysql-0  -c init-mysql
++ hostname
bash: line 2: hostname: command not found

The fix: I changed to this version you see. Essentially if the (current) hostname command fails, then it tries the next best thing: cat /etc/hostname . This worked like a charm, as seen in subsequent logs:

$ kubectl -n workshop logs mysql-0  -c init-mysql
++ hostname
bash: line 2: hostname: command not found
+ hostname=
++ cat /etc/hostname
+ hostname=mysql-0
+ [[ mysql-0 =~ -([0-9]+)$ ]]
+ ordinal=0
+ echo '[mysqld]'
+ echo server-id=100
+ [[ 0 -eq 0 ]]
+ cp /mnt/config-map/master.cnf /mnt/conf.d/

As seen above, despite the failed hostname command, the second option succeeded and the stateful sets pods (mysql-0 and mysql-1) get created successfully