Create S3 Bucket with Versioning enabled
aws s3api create-bucket --bucket cloudgeeks-terraform --region us-east-1
aws s3api put-bucket-versioning --bucket cloudgeeks-terraform --versioning-configuration Status=Enabled
if [ -d /root/.ssh ]
then
echo "/root/.ssh exists"
else
mkdir -p /root/.ssh
fi
if [ -f /root/.ssh/*.pem ]
then
echo "pem is there, I am removing it"
rm -f ~/.ssh/*.pem
export SSH_KEY_NAME="terraform-cloudgeeks"
aws ec2 create-key-pair --key-name "${SSH_KEY_NAME}" --query 'KeyMaterial' --output text > ~/.ssh/${SSH_KEY_NAME}.pem
else
echo "All is well, now I am creating fresh PEM"
export SSH_KEY_NAME="terraform-cloudgeeks"
aws ec2 create-key-pair --key-name "${SSH_KEY_NAME}" --query 'KeyMaterial' --output text > ~/.ssh/${SSH_KEY_NAME}.pem
fi
if [ -d /root/.kube ]
then
echo "/root.kube directory exists"
else
mkdir /root/.kube && touch /root/.kube/config
fi
kubectl logs -f -n karpenter $(kubectl get pods -n karpenter -l karpenter=controller -o name)
kubectl create deployment <Deplyment-Name> --image=<Container-Image>
kubectl create deployment first-deployment --image=quickbooks2018/blue:latest
kubectl scale --replicas=20 deployment/<Deployment-Name>
kubectl scale --replicas=20 deployment/first-deployment
Metrics Server Installation
kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml
kubectl get deployment metrics-server -n kube-system
kubectl get pods -n kube-system -l k8s-app=metrics-server
To create a php-apache deployment, run the following command:
kubectl create deployment php-apache --image=k8s.gcr.io/hpa-example
To set the CPU requests, run the following command:
kubectl patch deployment php-apache -p='{"spec":{"template":{"spec":{"containers":[{"name":"hpa-example","resources":{"requests":{"cpu":"200m"}}}]}}}}'
To expose the deployment as a service, run the following command:
kubectl create service clusterip php-apache --tcp=80
To create an HPA, run the following command:
kubectl autoscale deployment php-apache --cpu-percent=50 --min=1 --max=10
To confirm that the HPA was created, run the following command:
kubectl get hpa
kubectl describe hpa
To test a load on the pod in the namespace that you used in step 1, run the following:
kubectl run -i --tty load-generator --rm --image=busybox --restart=Never -- /bin/sh -c "while sleep 0.01; do wget -q -O- http://php-apache; done"
while sleep 0.01; do wget -q -O- http://php-apache; done
To see how the HPA scales the pod based on CPU utilization metrics, run the following command (preferably from another terminal window)
To clean up the resources used for testing the HPA, run the following commands:
kubectl delete hpa,service,deployment php-apache
kubectl delete pod load-generator
kubectl top --help
kubectl top node
kubectl top pod -A
kubectl top pod --containers -A