Skip to content

Instantly share code, notes, and snippets.

@hickeyma
Last active September 19, 2018 15:50
Show Gist options
  • Save hickeyma/c3413fadbdd8be8ea660903e084fd66d to your computer and use it in GitHub Desktop.
Save hickeyma/c3413fadbdd8be8ea660903e084fd66d to your computer and use it in GitHub Desktop.

Lab 2. I need to change but none of the hassle

We now would like to update the deployed application from ClusterIP to NodePort. How easy is it to do this?

1. Update the application using kubectl

In this part of the lab we will update the previously deployed application mychartapp, using Kubernetes directly.

  1. Get the YAML for the myapp service:

    $ kubectl -n default get service myapp -o yaml --export > myapp-svc.yaml

  2. Change to NodePort type

    $ sed 's/ClusterIP/NodePort/' myapp-svc.yaml > new-myapp-svc.yaml

  3. Delete the current service

    $ kubectl delete svc myapp

  4. Recreate the service with NodePort

    $ kubectl create -f new-myapp-svc.yaml

    To check the service, you can run kubectl get svc myapp

    NAME      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 (32651 in this output case) and this is the external proxy port into the service.

  5. To access the nginx server when "NodePort" is enabled, go to the following URL:

    http://$NODE_IP:$NODE_PORT

    The "$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:

    nginx image

2. Update the application using Helm

In this part of the lab we will update the previously deployed application mychartapp, using Helm.

  1. Update the application

    $ helm upgrade --set service.type=NodePort mychartapp ./mychartapp

    You 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 upgrade command upgrades the app to a specified version of a chart and updates chart values of service.type to NodePort. 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 mychartapp

    NAME         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 (32446 in this output case) and this is the external proxy port into the service.

  2. To access the nginx server when "NodePort" is enabled, go to the following URL:

    http://$NODE_IP:$NODE_PORT

    The "$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:

    nginx image

3. Conclusion

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment