Getting started with Kubernetes

Install

Create a deployment

snap run microk8s.kubectl create deployment my-deployment --image=ahmadnazir/dummy-server:0.2

Make sure that it is created

k get deployments
k describe deployments

View the pod

k get pods

NAME                               READY   STATUS    RESTARTS   AGE
my-deployment-c5755fb5c-2n6s6   1/1     Running   0          13s

Expose deployment

snap run microk8s.kubectl expose deployment my-deployment --type=NodePort --port=8088 --name=my-service

Get the services

k get services

NAME               TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
my-deployment      NodePort    10.152.183.73   <none>        8088:31821/TCP   20s

Test service

IP=`k get services | grep my-service  | awk '{print $3}'`
curl -i -XGET "http://${IP}:8088"

Cleanup

k delete service my-service
k delete deployment my-deployment

References

Appendix

alias k="/usr/bin/snap run kubectl $@"