Once your Kubernetes cluster is running and kubectl
is configured you could run your first application with a few steps. This can be done using the imperative commands which doesn't need configuration files.
In order to run an application you need to provide a deployment name (bootcamp
), the container image location (docker.io/jocatalin/kubernetes-bootcamp:v1
) and the port (8080
)
$ kubectl run bootcamp --image=docker.io/jocatalin/kubernetes-bootcamp:v1 --port=8080
Confirm that it worked with:
$ kubectl get deployments
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
bootcamp 1 1 1 1 6s
To expose your application and make it accessible from the outside run:
$ kubectl expose deployment/bootcamp --type="LoadBalancer" --port 8080
Confirm that it worked with:
$ kubectl get services
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes 10.0.0.1 <none> 443/TCP 3m
bootcamp 10.3.245.61 104.155.111.170 8080:32452/TCP 2m
To access the services, use the external IP and the application port e.g. like this:
$ export EXTERNAL_IP=$(kubectl get service bootcamp --output=jsonpath='{.status.loadBalancer.ingress[0].ip}')
$ export PORT=$(kubectl get services --output=jsonpath='{.items[0].spec.ports[0].port}')
$ curl "$EXTERNAL_IP:$PORT"
Hello Kubernetes bootcamp! | Running on: bootcamp-390780338-2fhnk | v=1
The same could be done manually with the data provided in:
$ kubectl describe service bootcamp
Name: bootcamp
Namespace: default
Labels: run=bootcamp
Selector: run=bootcamp
Type: LoadBalancer
IP: 10.3.245.61
LoadBalancer Ingress: 104.155.111.170
Port: <unset> 8080/TCP
NodePort: <unset> 32452/TCP
Endpoints: 10.0.0.3:8080
... events and details left out ....
$ export NODE=104.155.111.170
$ export PORT=8080
Once this worked you can scale up your application with:
$ kubectl scale deployments/bootcamp --replicas=4
And check the result with:
$ kubectl get deployments
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
bootcamp 4 4 4 4 30s
$ curl "$EXTERNAL_IP:$PORT"
Hello Kubernetes bootcamp! | Running on: bootcamp-390780338-2fhnk | v=1
$ curl "$EXTERNAL_IP:$PORT"
Hello Kubernetes bootcamp! | Running on: bootcamp-390780338-gmtv5 | v=1
Mind the changing pod id.
In order to push out a new application version run:
kubectl set image deployments/bootcamp bootcamp=jocatalin/kubernetes-bootcamp:v2
And confirm it with:
$ curl "$EXTERNAL_IP:$PORT"
Hello Kubernetes bootcamp! | Running on: bootcamp-284539476-gafwev3 | v=2
Cleaning up is finally done with:
$ kubectl delete deployment bootcamp
$ kubectl delete service bootcamp