Avatar

Previous posts in the DevOps Series are available here.

In a constantly changing ecosystem of DevOps tools, it is hard to keep up with new solutions. And it’s even harder to be genuinely impressed by something new. But every once in a while, a new solution appears, making such a strong impression, that you have to include it in your essentials toolset.

As discussed during this series, one of DevOps main goals is to facilitate and automate the whole process – from software development to quality assurance to production. Think about it… what if developers could work locally on their code, while interacting transparently with their remote production environment? And I mean real transparency, like without any containers or kubernetes interaction.

Let me make it crystal clear: I am talking about developers locally coding with their own tools, and testing their software live on containers deployed in a real remote kubernetes cluster. No required knowledge about docker, kubectl, etc. This would be nirvana, right? Well, that’s exactly what Okteto offers!

Code locally with your own tools

Okteto offers developers the ability to locally code with their own tools, and test their software live on containers deployed in a real remote kubernetes cluster, with no required knowledge about docker containers or kubernetes.

Too good to be true? Let’s give it a try!

First you need to install it, and it will automatically work with the k8s cluster active in your kubectl configuration.

By now you should already know how to get a full myhero deployment working on your GKE cluster, so please go ahead and do it yourself. To make it simpler please configure it in ‘direct’ mode, so no myhero-mosca or myhero-ernst is required. Remember you just need to comment with # two lines in k8s_myhero_app.yml (under ‘env’ – ‘myhero_app_mode’). After deployment you should have the 3 required microservices: myhero-ui, myhero-app and myhero-data. Please make sure to configure myhero-ui and myhero-app as LoadBalancer, so they both get public IP addresses. Once the application is working we can try okteto.

Let’s say we are AngularJS developers, and we have been assigned to work on the web front-end microservice (myhero-ui).

First thing we would need to do is cloning the repo, and get into the resulting directory:

$ git clone https://github.com/juliogomez/myhero_ui.git
$ cd myhero_ui

Please make sure you have defined the following required 3 variables:

$ export myhero_spark_server=<your_spark_url>
$ export myhero_app_server=<your_api_url>
$ export myhero_app_key=<your_key_to_communicate_with_app_server>

Then we will have okteto automatically detect the programming language used in the repo, and generate the required manifests based on it. Please make sure to answer n when asked if you would like to create a Kubernetes deployment manifest. We do not need it, because we already have our own myhero-ui manifest, and for this demo we will replace the existing front-end microservice with a new one. We could also create a different deployment and work in parallel with the production one.

$ okteto create
JavaScript detected in your source. Recommended image for development: okteto/node:11
Which docker image do you want to use for your development environment? [okteto/node:11]:

Create a Kubernetes deployment manifest? [y/n]: n
✓ Cloud native environment created

Okteto will automatically create the new okteto.yml manifest, specifying the deployment target, working directory, port forwarding and some scripts.

We will need to make some changes to make that file work in our setup:

  • Change the deployment name from myheroui to myhero-ui
  • Configure it to automatically install and start the code, including the following command: [“yarn”, “start”]
  • Port mapping: if you take a look at our front-end’s package.json file, you will see it starts an HTTP server in port 8000, so we should change the mapping from 3000:3000 to 3000:8000

For your convenience the myhero-ui repo includes an already modified manifest you can use for this demo.

Now you should be good to activate your cloud native development environment.

$ okteto up --namespace myhero --file okteto_myhero-ui.yml
Okteto 0.7.1 is available, please upgrade.
 ✓ Environment activated!
   Ports:
   3000 -> 8000
   Cluster: gke_test-project-191216_europe-west1-b_example-cluster
   Namespace: myhero
   Deployment: myhero-ui

yarn run v1.12.3
$ npm install
npm WARN notice [SECURITY] ecstatic has the following vulnerability: 1 moderate. Go here for more details: https://nodesecurity.io/advisories?search=ecstatic&version=1.4.1 - Run `npm i npm@latest -g` to upgrade your npm version, and then `npm audit` to get more info.
npm notice created a lockfile as package-lock.json. You should commit this file.
added 24 packages from 27 contributors and audited 24 packages in 5.825s
found 1 moderate severity vulnerability
  run `npm audit fix` to fix them, or `npm audit` for details
$ http-server -a localhost -p 8000 -c-1 ./app
Starting up http-server, serving ./app
Available on:
  http://localhost:8000
Hit CTRL-C to stop the server

This process replaces the existing myhero-ui container deployment in the kubernetes cluster, with your new one. It will also synchronize files from your workstation to the development environment, and perform the required port forwarding. You may access this new web front-end deployment browsing to http://localhost:3000/

As a developer please use your favourite IDE (or even just vi) in your local workstation to edit, for example, the file defining the front page.

vi ./app/views/main.html

Make a change in your front page title, from ‘Make your voice heard!’ to ‘Make your voice hearRRRd!’, and save your file. Go back to your browser, refresh and you will see your changes reflected immediately!

Let that sink in for a second… as a developer you have modified your code from your local workstation, using your own IDE and tools. And okteto has transparently updated the deployment containers in your production kubernetes cluster. All of that without any docker or kubernetes interaction:

  • No need to run Docker locally in your workstation
  • No need to create and publish new Docker images after code changes
  • No need to manually update the deployment in your remote kubernetes cluster
  • No need to even know the docker or kubectl CLIs !

Okteto does everything for you and in a completely transparent way!

Developers can now easily test how their software changes behave when deployed as containers-based microservices in the real production kubernetes environment… without even knowing what Docker and kubernetes are!

Once you get over this overwhelming and amazing experience, you may disable your cloud native environment by pressing Ctrl+C and then Ctrl+D in your terminal window. From there you can remove your deployment and replace it with the original one, running:

$ okteto down

Julio Gomez DevOps

Any questions or comments please let me know in the comments section below, Twitter or LinkedIn.  See you in my next post, stay tuned!

 

Join DevNet: access the learning labs, docs, and sandboxes you need for network automation and application development.


We’d love to hear what you think. Ask a question or leave a comment below.
And stay connected with Cisco DevNet on social!

Twitter @CiscoDevNet | Facebook | LinkedIn

Visit the new Developer Video Channel



Authors

Julio Gomez

Programmability Lead, EMEAR

Systems Engineers