How to Deploy Your First React App to Kubernetes

For Full-stack developers shipping their first Kubernetes app · Based on Cloud Guru React-to-Kubernetes Deploy Method

// TL;DR

If you're a full-stack developer deploying your first app to Kubernetes, this method takes your working React app from localhost to a live cluster through four validated stages: run locally, containerize and test with Docker, rebuild inside your cloud provider's registry, then deploy and expose with NodePort. It emphasizes catching bugs early — a missing API key or port mismatch surfaces at the local stage, not after a full cloud deployment. Export your Docker username, match your Dockerfile port to the service port, and start with NodePort before touching LoadBalancer. The result is a repeatable, production-ready pipeline you'll reuse on every project.

Why does my first Kubernetes deployment keep breaking?

Most first-time Kubernetes failures come from skipping validation. You build an image, push it, create a deployment, and the page won't load — but now you have no idea whether the bug is in your code, your container, your registry, or your cluster config. The Cloud Guru React-to-Kubernetes Deploy Method solves this by validating at four distinct stages, so every bug is caught at the earliest point it can appear.

Start by running your app on bare metal. Clone the repo, run `npm install`, insert your API key into the actions or config file, then `npm run build:css` followed by `npm run start`. Open localhost and run a live query. If you see an 'invalid API key' error, stop and fix it here — never carry a broken key into Docker.

How do I containerize my React app correctly?

Export your Docker username first: `export DOCKER_USERNAME=your-username`. This single step is referenced in every build command and prevents malformed image tags. Then build with `docker build -t $DOCKER_USERNAME/image-name:latest .`, choosing an image name that matches your repo for clarity.

Expect deprecation warnings from older npm modules — they're non-fatal. Confirm the image exists with `docker images`. Then run it locally: `docker run -p host-port:container-port $DOCKER_USERNAME/image-name:latest`. Open localhost on that port and re-run your test query. Confirming the app works inside a container before pushing to the cloud isolates environment issues from deployment issues — a distinction that saves hours of debugging.

How do I get my image into the cloud and onto the cluster?

Here's the step most first-timers miss: managed Kubernetes clusters pull from their provider's own container registry, not Docker Hub. So you rebuild inside that registry. Authenticate with your cloud CLI (`bx login`), specify your region, and confirm your namespace exists — create one if this is your first deployment and record the exact string.

Then rebuild: `bx cr build -t registry.region.bluemix.net/namespace/image-name:latest .`. This is a fresh build inside the cloud ecosystem, not a push. Next, create your deployment: `kubectl run deployment-name --image=registry.region.bluemix.net/namespace/image-name:latest`, and confirm with `kubectl get deployments`.

How do I expose and access my deployed app?

Expose it as a NodePort — the simplest option for a first deployment: `kubectl expose deployment deployment-name --type=NodePort --name=service-name --port=port`. Critically, that port must match the EXPOSE value in your Dockerfile exactly. This is a hard contract; a mismatch gives you a service that looks healthy but is silently unreachable.

To build your public URL, get the worker IP with `bx cs workers cluster-name` and the NodePort from `kubectl describe service service-name`. Combine them as `PublicIP:NodePort`, open it in a browser, and run a live query. Your React app is now live on Kubernetes.

If the page won't load, your checklist is short: confirm the expose port matches the Dockerfile EXPOSE value, and confirm you used the correct worker IP. Resist the urge to reach for LoadBalancer on a first deployment — it requires extra networking config and is harder to debug. NodePort is enough to validate everything works.

Next step: Clone a sample React Code Pattern, export your Docker username, and walk through all 11 steps once end to end. Once you've done it manually, you'll have the mental model to automate it in CI/CD later.

// FREQUENTLY ASKED QUESTIONS

Do I need Kubernetes experience to follow this method?

No. The method is designed for first-time deployers and uses imperative kubectl commands — run, expose, get, describe — that are easy to reason about. It defaults to NodePort, which needs no extra networking config, so you can get a live deployment without understanding advanced cluster topology. You pick up the concepts as you move through each validated stage.

What's the one step first-timers skip most often?

Rebuilding the image inside the cloud container registry. Developers assume a Docker Hub push is enough, but managed Kubernetes clusters pull from their own provider's registry. Always run the cloud-specific build command like 'bx cr build' with your namespace and region before creating the deployment.

How long does a first deployment take with this method?

Allowing time for npm install, Docker builds, and cloud registry builds, expect under an hour for a first run if your API key and namespace are ready. Subsequent deployments are faster because the pipeline is repeatable and you already have your Docker username, namespace, and port contract established.