
So far, odo
has been mainly focusing on container development on Kubernetes and OpenShift clusters.
In this post, we will showcase the experimental support we have recently added for Podman.
We will see how odo
can leverage Podman for local development in containers with no requirement whatsoever on any cluster โ making it easier to iterate on the application locally and transition to Kubernetes or OpenShift later on.
Prerequisitesโ
odo
3.3.0 or later. Support for Podman was added as an experimental feature in 3.3.0; so we recommend you install the latest version ofodo
.- Podman.
- Podman Desktop, optional.
Working locally with Podmanโ
Let's revisit one of our quickstart guides, say the Golang one, to make it work with Podman.
Step 0. Creating the initial source code (optional)โ
We will create the example source code by using some popular frameworks.
Before we begin, we will create a new directory and cd into it.
mkdir quickstart-demo && cd quickstart-demo
This is optional and you may use an existing project instead (make sure you cd
into the project directory before running any odo commands) or a starter project from odo init
.
For Go, we will create our own application using the standard library:
- Create the following
main.go
file:
package main
import (
"fmt"
"log"
"net/http"
)
func main() {
const addr = "0.0.0.0:8080"
http.HandleFunc("/", HelloServer)
log.Println("Up and running on", addr)
http.ListenAndServe(addr, nil)
}
func HelloServer(w http.ResponseWriter, r *http.Request) {
log.Println("New request:", *r)
fmt.Fprintf(w, "Hello, %s!", r.URL.Path[1:])
}
- Initialize a
go.mod
file:
go mod init my.example.go.project
Example
Your source code has now been generated and created in the directory.
Step 1. Initializing your application (odo init
)โ
Now we'll initialize the application by creating a devfile.yaml
to be deployed.
odo
handles this automatically with the odo init
command by auto-detecting the source code and downloading the appropriate Devfile.
Note: If you skipped Step 0, select a "starter project" when running odo init
.
Let's run odo init
and select Go
:
odo init
Sample Output
Step 2. Enabling the experimental modeโ
Because the support for Podman is still experimental at the time of writing, we first need to explicitly opt-in.
Enabling the experimental mode can be done by setting the ODO_EXPERIMENTAL_MODE
environment variable to true
in the terminal session, like so:
export ODO_EXPERIMENTAL_MODE=true
Step 3. Iterating on your application locally on containers (odo dev
)โ
Now that we've generated our code as well as our Devfile, let's start iterating on our application locally by starting a Development session with odo dev
,
but targeting our local Podman.
odo dev
on Podman will use the same inner loop development as for the cluster mode,
allowing you to code, build, run and test the application in a continuous workflow.
Once you run odo dev --platform=podman
, you can freely edit the application code in your favorite IDE and watch as odo
rebuilds and redeploys it.
Let's run odo dev --platform=podman
to start development on your Go
application:
odo dev --platform=podman
Sample Output
You can now access the application at 127.0.0.1:20001 in your local browser and start your development loop. odo
will watch for changes and push the code for real-time updates.
Example
We can optionally open the Podman Desktop application to take a look at the resources odo
has created for our application on Podman:
Wrapping Upโ
odo
is now able to work with Podman to accelerate local development in containers, without requiring you to have access to any Kubernetes cluster.
Note that our support for Podman is still experimental, but we are working on improving the feature parity (as much as possible) with the cluster mode.
As such, any feedback is highly appreciated.