Pushing microservice updates into Kubernetes

Let's now try making a change to our service. For experimentation purposes, let's copy the micro folder to micro2 as we make these changes.

Let's edit the micro/adderservice/service.js file and add some console.log statements so that it looks as follows:

module.exports = service

function service () {
function add (args, cb) {
const {first, second} = args
console.log(`add called: ${first} ${second}`)
const result = (parseInt(first, 10) + parseInt(second, 10))
cb(null, {result: result.toString()})
}

return { add }
}

No we'll quickly rebuild and push our container to DockerHub:

$ cd micro2/adderservice
$ docker build -t adderservice .
$ docker tag adderservice <dockerhub-account>/adderservice:2
$ docker push <dockerhub-account>/adderservice:2

Notice that we applied a version tag this time, rather than using the default latest tag. Also notice that when we push Docker only needs to push a single layer, reporting that the other layers already exist.

Now let's update our deployment.

Firstly, we'll edit the micro/deployment/adderservice-dep.yml file and update the image field to reflect the tag of the image that we just pushed. The line should read as follows:

    image: <dockerhub-account>/adderservice:2 

Next, we need to tell Kubernetes to apply the change, like so:

$ cd micro2/deployment
$ kubectl apply -f adderservice-dep.yml

Finally, we'll test our service and check that our log statement shows up.

As before, we can use the get services command to fetch the port mappings:

$ kubectl get services 

We can use curl to hit the service endpoint (assuming port 30532):

$ curl http://192.168.99.100:30532/add/1/2 

If we open the dashboard (by running minikube dashboard) and view the logs, we should see our inserted message in the log output:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset