Clone this repository and go to the directory:
git clone $REPO
cd guestbook
Create our Dockerfile in the guestbook directory
cd guestbook
vim Dockerfile
cd guestbook
docker build .
docker tag $image_id_from_before sbpdemo/guestbook
docker run -p 80:80 sbpdemo/guestbook
docker run -p 80:80 -d sbpdemo/guestbook
docker run -p 80:80 --mount source=test,target=/usr/src/app/db -d sbpdemo/guestbook
docker kill $your_container_id
docker run -p 80:80 --mount source=test,target=/usr/src/app/db -d sbpdemo/guestbook
docker run -p 80:80 --env NAME="$your_name" --mount source=test,target=/usr/src/app/db/ -d sbpdemo/guestbook
cd tweakers-workshop
./workshop.sh connect ${your_user_id}
mv ~/.kube/config my_kube_config_backup
mv user22.kubeconfig ~/.kube/config
Alternatively, you can add kubeconfig --kubeconfig ${user_id}.kubeconfig
to all of your commands
docker tag sbpdemo/guestbook sbpdemo/guestbook:${user_ID}
docker login
If you are already logged into another account, please log out of it first (or feel free to use your own docker hub account if you prefer)
docker push sbpdemo/guestbook:${user_ID}
kubectl run my-guestbook --image sbpdemo/guestbook:${user_id}
Check on the pods and get the pod name:
kubectl get pods
And port-forward to it, replacing the pod name with your pod name:
kubectl port-forward my-guestbook-54cc64dbcf-fwds2 8080:80
kubectl expose deployment my-guestbook --type=LoadBalancer --port=80
Get the service cname:
$ kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 100.64.0.1 <none> 443/TCP 2d
my-guestbook LoadBalancer 100.67.30.86 a8ef38fb4cfcb11e89b610afb2428ec8-705870703.eu-west-1.elb.amazonaws.com 80:32567/TCP 39s
And you can now open it in your browser
kubectl delete deployment my-guestbook
kubectl run my-guestbook --image sbpdemo/guestbook:user1 --env NAME=${your_name_here}
kubectl apply -f mariadb/
Get the pod name:
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
my-guestbook-5cd7c6b86d-jbq29 1/1 Running 0 2m
mysql-5766c846b5-jx5qf 1/1 Running 0 2m
Port-forward:
$ kubectl port-forward mysql-5766c846b5-jx5qf 3306
Forwarding from 127.0.0.1:3306 -> 3306
Forwarding from [::1]:3306 -> 3306
Now open a new shell/powershell window
Test the connection:
docker run -it mysql:5.6 mysql -h host.docker.internal -u root -p
The password is 'password'
And import the schema:
$ docker run -i mysql:5.6 mysql -h host.docker.internal -u root -ppassword < guestbook/database.sql
Warning: Using a password on the command line interface can be insecure.
Handling connection for 3306
Confirm the table is created:
docker run -it mysql:5.6 mysql -h host.docker.internal -u root -p messages -e "SHOW TABLES;"
Enter password:
Handling connection for 3306
+--------------------+
| Tables_in_messages |
+--------------------+
| messages |
+--------------------+
kubectl patch deployment mysql -p '{"spec":{"template":{"spec":{"containers":[{"name":"mysql","image":"sbpdemo/mysql:5.6"}]}}}}'
kubectl delete deployment my-guestbook
kubectl run my-guestbook --image sbpdemo/guestbook:user1 --env NAME=Andy --env DATABASE_TYPE="mysql"
kubectl create -f quotas-limits/quota.yml
kubectl scale deployment my-guestbook --replicas=10
You can see the quota prevented the scale up:
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
my-guestbook-7965b5f789-ck9jv 1/1 Running 0 8m
mysql-5d76fb8d49-dxnnb 1/1 Running 0 9m
$ kubectl get replicasets
NAME DESIRED CURRENT READY AGE
my-guestbook-7965b5f789 10 1 1 22m
mysql-5d76fb8d49 1 1 1 19m
kubectl describe replicaset my-guestbook-7965b5f789
Name: my-guestbook-7965b5f789
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal SuccessfulCreate 24m replicaset-controller Created pod: my-guestbook-7965b5f789-dbctw
~~~Truncated~~~
Warning FailedCreate 3m23s replicaset-controller Error creating: pods "my-guestbook-7965b5f789-j2wkr" is forbidden: failed quota: k8s-quota: must specify limits.cpu,limits.memory,requests.memory
Warning FailedCreate 2m3s (x6 over 3m22s) replicaset-controller (combined from similar events): Error creating: pods "my-guestbook-7965b5f789-wdhgm" is forbidden: failed quota: k8s-quota: must specify limits.cpu,limits.memory,requests.memory
kubectl delete deployment my-guestbook
kubectl run my-guestbook --image sbpdemo/guestbook:user1 --env NAME=Andy --env=DATABASE_TYPE=mysql --requests='cpu=100m,memory=256Mi' --limits='cpu=150m,memory=512Mi' --replicas=10
The quota prevented more than four pods from starting:
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
my-guestbook-97f659799-6jmq9 1/1 Running 0 1m
my-guestbook-97f659799-9c4p6 1/1 Running 0 1m
my-guestbook-97f659799-btxcs 1/1 Running 0 1m
my-guestbook-97f659799-x9w59 1/1 Running 0 1m
mysql-5d76fb8d49-dxnnb 1/1 Running 0 15m
Another describe of the replica set shows this:
$ kubectl describe replicaset my-guestbook-97f659799
Warning FailedCreate 3m30s replicaset-controller Error creating: pods "my-guestbook-97f659799-kdm8g" is forbidden: exceeded quota: k8s-quota, requested: limits.memory=512Mi, used: limits.memory=2Gi, limited: limits.memory=2Gi