We now would like to update the deployed application from ClusterIP to NodePort. How easy is it to do this?
In this part of the lab we will update the previously deployed application mychartapp, using Kubernetes directly.
-
Get the YAML for the
myappservice:$ kubectl -n default get service myapp -o yaml --export > myapp-svc.yaml -
Change to NodePort type
$ sed 's/ClusterIP/NodePort/' myapp-svc.yaml > new-myapp-svc.yaml -
Delete the current service
$ kubectl delete svc myapp -
Recreate the service with NodePort
$ kubectl create -f new-myapp-svc.yamlTo check the service, you can run
kubectl get svc myappNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE myapp NodePort 10.105.169.131 <none> 80:32651/TCP 1m
Note: A new port has been allocated (
32651in this output case) and this is the external proxy port into the service. -
To access the nginx server when "NodePort" is enabled, go to the following URL:
http://$NODE_IP:$NODE_PORTThe "$NODE_IP:$NODE_PORT" can be found as per the instructions notes in the upgrade output as shown in Step 1. above.
The output should be similar to the following:
In this part of the lab we will update the previously deployed application mychartapp, using Helm.
-
Update the application
$ helm upgrade --set service.type=NodePort mychartapp ./mychartappYou should see output similar to the following:
Release "mychartapp" has been upgraded. Happy Helming! LAST DEPLOYED: Wed Sep 19 14:10:13 2018 NAMESPACE: default STATUS: DEPLOYED RESOURCES: ==> v1/Service NAME AGE mychartapp 27m ==> v1beta2/Deployment mychartapp 27m ==> v1/Pod(related) NAME READY STATUS RESTARTS AGE mychartapp-66f56ffc77-z8qs6 1/1 Running 0 27m NOTES: 1. Get the application URL by running these commands: export NODE_PORT=$(kubectl get --namespace default -o jsonpath="{.spec.ports[0].nodePort}" services mychartapp) export NODE_IP=$(kubectl get nodes --namespace default -o jsonpath="{.items[0].status.addresses[0].address}") echo http://$NODE_IP:$NODE_PORT
The
upgradecommand upgrades the app to a specified version of a chart and updates chart values ofservice.typetoNodePort. As "NodePort" exposes the service on the Node’s IP at a static port, you can now connect to the service from outside the cluster. You can also see that the "NOTES" output has changed to the "NodePort" service information.To check the service, you can run
kubectl get svc mychartappNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE mychartapp NodePort 10.109.162.157 <none> 80:32446/TCP 39m
Note: A new port has been allocated (
32446in this output case) and this is the external proxy port into the service. -
To access the nginx server when "NodePort" is enabled, go to the following URL:
http://$NODE_IP:$NODE_PORTThe "$NODE_IP:$NODE_PORT" can be found as per the instructions notes in the upgrade output as shown in Step 1. above.
The output should be similar to the following:
Congratulations, you have now updated the applications! This is a "no brainer"; Helm is so much easier!. We will drill into a more complex example to further enhance this.
Why not check out Lab 3.
