Pre-requisites:
Install Docker client/server
Install K8s cluster.
In the K8s Master Node.
git clone https://github.com/spring-guides/gs-spring-boot-docker
cd gs-spring-boot-docker/complete
./mvnw install -e -X # This will create a .jar file in the newely created target directory.
sudo docker build -t image-sb1 -f Dockerfile .
sudo docker images
sudo docker tag image-sb1 trow.kube-public:31000/myrepo # Tag the new image with your private registry (Optional)
sudo docker push trow.kube-public:31000/myrepo # Push the new image to your local private registry (Optional)
kubectl run image-sb --image=trow.kube-public:31000/myrepo --port=8080
kubectl expose deployment/image-sb --type="NodePort" --port 8080
Testing:
----------------------------------------------------------------------
ubuntu@namenode:~$ kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1
image-sb NodePort 10.102.38.118
ubuntu@namenode:~$ curl 10.102.38.118:8080
Hello Docker World
----------------------------------------------------------------------
ubuntu@namenode:~$ kubectl get pods
NAME READY STATUS RESTARTS AGE
image-sb-76448df777-mxwqq 1/1 Running 0 72m
The below command will get you inside the k8s pod image-sb-76448df777-mxwqq
# wget localhost:8080
Connecting to localhost:8080 (127.0.0.1:8080)
index.html 100% |************************************************************************************************************************| 18 0:00:00 ETA
#
----------------------------------------------------------------------
Take the url
That is all .. Cheers :-)
Comments