DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
Securing Your Software Supply Chain with JFrog and Azure
Register Today

Trending

  • What Is React? A Complete Guide
  • How To Use an Automatic Sequence Diagram Generator
  • Low Code vs. Traditional Development: A Comprehensive Comparison
  • Rule-Based Prompts: How To Streamline Error Handling and Boost Team Efficiency With ChatGPT

Trending

  • What Is React? A Complete Guide
  • How To Use an Automatic Sequence Diagram Generator
  • Low Code vs. Traditional Development: A Comprehensive Comparison
  • Rule-Based Prompts: How To Streamline Error Handling and Boost Team Efficiency With ChatGPT
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Local Development With OpenShift and Tilt

Local Development With OpenShift and Tilt

How to use Tilt to facilitate local OpenShift development. If you develop containerized applications on OpenShift, this post is for you.

Ales Nosek user avatar by
Ales Nosek
·
Jun. 16, 20 · Tutorial
Like (2)
Save
Tweet
Share
2.66K Views

Join the DZone community and get the full member experience.

Join For Free

in this article, i am going to show you how to use tilt to facilitate local openshift development. tilt's capabilities will be demonstrated in a practical example that uses buildah and codeready containers. if you develop containerized applications on openshift, this blog post is for you.

how does tilt facilitate local development?

the diagram below depicts a development workflow orchestrated by tilt. after you execute the tilt up command on your development machine, tilt will keep running while performing the following actions:

  1. tilt watches for changes in the source code made by the developer on the local machine.
  2. after a change has been detected, tilt executes buildah to update the container image. after the build completes, the updated container image is pushed to the internal registry in codeready containers.
  3. tilt watches kubernetes manifests on the local machine and keeps them in sync with codeready containers. any changes made to the manifests are instantly applied to codeready containers.
  4. tilt forwards local ports to the application pod running in codeready containers. this allows the developer to conveniently access the application on localhost.
infographic

tilt helps the developer automate many of the manual steps made during the development of containerized applications. it speeds up the edit-compile-run loop considerably. interested to trying it out? follow me to the next section, where we will implement the workflow depicted in the above diagram.

using tilt for developing a sample application

in this section, we are going to use tilt to orchestrate the development of a sample application. as i didn't want to reinvent the wheel by designing a custom application, i grabbed the plain old static html example that comes with tilt and can be found on github . this example is described in the tilt's documentation and you may already be familiar with it. it consists of a very simple shell script that serves a static html. in contrast to tilt's example which leverages docker and upstream kubernetes, i will be using developer tools from the red hat's portfolio:

  • buildah
  • ubi container images
  • codeready containers

in order to be able to use the red hat developer tools, i had to modify the original sample code. the sample code used in this tutorial can be found on github . i recommend that you go ahead and briefly review it.

the overall setup consists of a fedora 32 development machine where i installed buildah and coreready containers (crc) version 1.10. i installed tilt version 0.13.4 which is the latest release of tilt available at the time of this writing. if you plan to use tilt along with codeready containers, i recommend grabbing this or any future versions of tilt, as this version includes a patch that makes tilt work with codeready containers without the need for further configuration. the tilt binary can be downloaded from github .

having the required tools in place, let's start by logging in into crc and creating a new project:

shell




x


1
$ oc login
2
$ oc new-project tilt-example


let's now focus on configuring buildah to be able the pull and push images from the container registries. as you can see in the dockerfile , our application uses the registry.redhat.io/ubi8/ubi container image as the base image. in order for buildah to be able to pull this image from the registry, we need to log in to this registry using the red hat customer portal credentials:

shell




xxxxxxxxxx
1


1
$ buildah login registry.redhat.io



next, let's configure buildah to be able to push images into the crc internal registry. the crc registry endpoint uses a self-signed certificate. buildah will refuse to communicate with the internal registry as the certificate is signed by an unknown authority. in order for buildah to be able to push images into the internal registry, you will need to add this registry to the list of insecure registries. on your development machine, edit /etc/containers/registries.conf and add the crc internal registry to the list of insecure registries.

shell




xxxxxxxxxx
1


1
[registries.insecure]
2
registries = [ 'default-route-openshift-image-registry.apps-crc.testing' ]



in order for buildah to be able to push images into the crc registry, we need to log in to this registry. for that, use the oc command to grab a token used for authentication against the registry:

shell




xxxxxxxxxx
1


1
$ oc whoami --show-token
2
7getdza6mqa-nexwetxtofujtehocvshkl5yxtxqeb0



log in to the registry using the authentication token:

shell




xxxxxxxxxx
1


1
$ buildah login \
2
    --username unused \
3
    --password 7getdza6mqa-nexwetxtofujtehocvshkl5yxtxqeb0 \
4
    default-route-openshift-image-registry.apps-crc.testing
5
login succeeded!



after successfully logging into the crc internal registry, the buildah configuration is now complete. finally, we can turn our attention to tilt. first, let's review the tiltfile which describes how tilt will orchestrate our development workflow:

shell




xxxxxxxxxx
1
17


1
# push the container image to the crc internal registry, project tilt-example
2
default_registry(
3
  'default-route-openshift-image-registry.apps-crc.testing/tilt-example',
4
  host_from_cluster='image-registry.openshift-image-registry.svc:5000/tilt-example')
5

           
6
# use buildah to build and push the container image
7
custom_build(
8
  'example-html-image',
9
  'buildah build-using-dockerfile --tag $expected_ref . && buildah push $expected_ref',
10
  ['.'],
11
  skips_local_docker=true)
12

           
13
# deploy kubernetes resource
14
k8s_yaml('kubernetes.yaml')
15

           
16
# make the application available on localhost:8000
17
k8s_resource('example-html', port_forwards=8000)



i annotated the tiltfile with comments that explain the meaning of individual tilt instructions. ready to give it a shot? just clone the git repository and run tilt:

shell




xxxxxxxxxx
1


1
$ git clone https://github.com/noseka1/local-development-with-openshift-and-tilt
2
$ cd local-development-with-openshift-and-tilt/
3
$ tilt up



after tilt comes up, it will call buildah to pull the base image, build the application, and push the resulting image to the crc internal registry. it will also deploy the application on kubernetes by applying the kubernetes.yaml manifest referenced in the tiltfile . if everything worked well, and the application pod starts up, you will see the "serving files on port 8000" log message in the bottom pane:


at this point, you should be able to reach the running application on localhost:8000 :

shell




xxxxxxxxxx
1
10


1
$ curl localhost:8000
2
<!doctype html>
3
<html>
4
  <body style="font-size: 30px; font-family: sans-serif; margin: 0;">
5
    <div style="display: flex; flex-direction: column; width: 100vw; height: 100vh; align-items: center; justify-content: center;">
6
      <img src="pets.png" style="max-width: 30vw; max-height: 30vh;">
7
      <div>hello cats!</div>
8
    </div>
9
  </body>
10
</html>



to experience how tilt facilitates the local development, change the content of the index.html file. after you save your changes, tilt will instantly re-run the loop and deploy the updated application.

conclusion

in this blog, we described how tilt can facilitate the local development of containerized applications. we demonstrated tilt's capabilities in a practical example that showed tilt working along with buildah and codeready containers. in this introductory article, we were able to only scratch the surface. there is much more that tilt has to offer, including live updates that can update the application without restarting the container, and which can drastically speed up the edit-compile-run loop. i encourage you to read through tilt's documentation to learn more about this tool.

do you use tilt for development on openshift or kubernetes? what's your opinion on tilt? i would be happy to hear about your experiences. you can leave your comments in the comment section below.

Kubernetes Docker (software) application OpenShift shell

Published at DZone with permission of Ales Nosek. See the original article here.

Opinions expressed by DZone contributors are their own.

Trending

  • What Is React? A Complete Guide
  • How To Use an Automatic Sequence Diagram Generator
  • Low Code vs. Traditional Development: A Comprehensive Comparison
  • Rule-Based Prompts: How To Streamline Error Handling and Boost Team Efficiency With ChatGPT

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: