');mask-image:url('data:image/svg+xml;utf8, ');content:"";margin:0 .4rem;display:inline-block;vertical-align:middle;line-height:1}.breadcrumb-trail .trail-items li:last-child:after{display:none}.bloglo-breadcrumbs{font-size:1.4rem;border-width:0}#bloglo-copyright .bloglo-flex-row>div:empty{display:none}#bloglo-copyright>.bloglo-container>.bloglo-flex-row>div{width:auto;padding-top:.6rem;padding-bottom:.6rem}.bloglo-copyright-layout-1 #bloglo-copyright>.bloglo-container>.bloglo-flex-row>div{-ms-flex-preferred-size:100%;flex-basis:100%;-ms-flex-negative:0;flex-shrink:0;-webkit-box-pack:center;-ms-flex-pack:center;justify-content:center}#bloglo-scroll-top{-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:center;-ms-flex-pack:center;justify-content:center;position:fixed;bottom:2.5rem;right:2rem;z-index:997;width:4rem;height:4rem;opacity:0;-webkit-transform:translate3d(0,3rem,0);transform:translate3d(0,3rem,0)}#bloglo-scroll-top .bloglo-scroll-icon{overflow:hidden;z-index:2}#bloglo-scroll-top .bloglo-icon{-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:center;-ms-flex-pack:center;justify-content:center;height:2rem;color:var(--bloglo-white);-webkit-transform:translateY(1.1rem);-ms-transform:translateY(1.1rem);transform:translateY(1.1rem)}#bloglo-scroll-top:before{content:"";z-index:1;border-radius:10rem;background-color:var(--bloglo-primary);-webkit-transform:scale(1);-ms-transform:scale(1);transform:scale(1);border:.1rem solid rgba(190,190,190,.3)}#bloglo-scroll-top svg{fill:var(--bloglo-white)}.entry-meta{font-size:1.4rem;margin-top:1.2rem}.entry-meta .bloglo-icon{height:1.827rem;margin-right:.7rem;vertical-align:text-bottom}.entry-meta .entry-meta-elements>span{padding:0 1.1rem;line-height:1.2}.entry-meta .entry-meta-elements>span{-js-display:inline-flex;display:-webkit-inline-box;display:-ms-inline-flexbox;display:inline-flex;-webkit-box-align:center;-ms-flex-align:center;align-items:center}.entry-meta .entry-meta-elements>span:first-child{padding-left:0}.entry-meta .entry-meta-elements>span:last-child{margin-right:0;padding-right:0}.entry-meta .entry-meta-elements>span:before{content:"";height:1.6rem;width:.1rem;background-color:rgba(0,0,0,.25);position:relative;left:-1.1rem}.entry-meta .entry-meta-elements>span:first-child:before{display:none}.entry-media{margin-bottom:3rem}.entry-media img{margin:0 auto;display:block}.single-post .entry-media{margin-top:4rem}.single-post .entry-media{margin-bottom:4rem}.single .post-category{margin-bottom:.3rem;font-size:1.4rem}.single .post-category a{-js-display:inline-flex;display:-webkit-inline-box;display:-ms-inline-flexbox;display:inline-flex;font-weight:500;padding:.6rem 1rem;line-height:1;border-radius:var(--bloglo-normal-radius);text-decoration:none;margin:0 .4rem .8rem}.single .post-category a{border-width:.2rem;border-style:solid}.single .post-category a:first-of-type{margin-left:0}.single .entry-header{text-align:left;margin-bottom:1rem}.single .entry-meta{text-align:left;margin-top:1.6rem}.single.bloglo-page-title-align-left .bloglo-article>.entry-header,.single.bloglo-page-title-align-left .bloglo-article>.post-category{text-align:left}.single.bloglo-page-title-align-left .bloglo-article>.entry-meta>.entry-meta-elements{-webkit-box-pack:start;-ms-flex-pack:start;justify-content:flex-start}button.bloglo-animate-arrow{-webkit-appearance:none;border:none;-webkit-box-shadow:none;box-shadow:none;background:0 0;outline:none}.bloglo-animate-arrow .arrow-bar{-webkit-transform:scaleX(0);-ms-transform:scaleX(0);transform:scaleX(0)}.bloglo-animate-arrow svg{vertical-align:middle}.bloglo-animate-arrow.right-arrow svg{-webkit-transform:rotate(180deg);-ms-transform:rotate(180deg);transform:rotate(180deg)}.bloglo-animate-arrow.right-arrow .arrow-bar{-webkit-transform-origin:100% 0;-ms-transform-origin:100% 0;transform-origin:100% 0}.bloglo-animate-arrow.right-arrow .arrow-handle{-webkit-transform:translateX(.6rem);-ms-transform:translateX(.6rem);transform:translateX(.6rem)}.bloglo-hamburger{padding:0;display:inline-block;font:inherit;color:inherit;text-transform:none;background-color:transparent;border:0;margin:0;overflow:visible}.hamburger-box{width:2.5rem;height:1.4rem;display:inline-block;position:relative}.hamburger-inner{display:block;top:50%;margin-top:-.1rem}.hamburger-inner,.hamburger-inner:before,.hamburger-inner:after{width:2.8rem;height:2px;background-color:#232323;border-radius:var(--bloglo-normal-radius);position:absolute}.hamburger-inner:before,.hamburger-inner:after{content:"";display:block}.hamburger-inner:before{top:-5px}.hamburger-inner:after{bottom:-5px}.bloglo-mobile-nav{display:none;margin-left:2.4rem}.bloglo-hamburger,.bloglo-mobile-nav{-webkit-box-align:center;-ms-flex-align:center;align-items:center}body:not(.is-mobile-menu-active) .bloglo-hamburger .hamburger-box .hamburger-inner:before{width:1.5rem}.bloglo-hamburger{-js-display:inline-flex;display:-webkit-inline-box;display:-ms-inline-flexbox;display:inline-flex;border-radius:var(--bloglo-normal-radius)}.bloglo-hamburger .hamburger-inner,.bloglo-hamburger .hamburger-inner:before,.bloglo-hamburger .hamburger-inner:after{background-color:currentColor}button.bloglo-hamburger{outline:none}#bloglo-header:after{content:"";position:fixed;top:100%;left:0;right:0;height:100vh;background-color:rgba(255,255,255,.85);z-index:991;opacity:0;visibility:hidden;will-change:opacity,visibility;-webkit-transform:translate3d(0,0,0);transform:translate3d(0,0,0)}@media only screen and (min-width:783px){.site .bloglo-flex-row .col-md{-webkit-box-flex:1;-ms-flex-positive:1;flex-grow:1;-ms-flex-negative:1;flex-shrink:1;max-width:100%;-ms-flex-preferred-size:0;flex-basis:0}.site .bloglo-flex-row .col-md.flex-basis-auto{-ms-flex-preferred-size:auto;flex-basis:auto}.site .bloglo-flex-row .end-md{-webkit-box-pack:end;-ms-flex-pack:end;justify-content:flex-end;text-align:end;margin-left:auto}}@media screen and (max-width:768px){.bloglo-hide-mobile-tablet{display:none!important}.bloglo-container{padding:0 3rem}.bloglo-header-widgets .bloglo-header-widget{padding-left:1rem;padding-right:1rem}.bloglo-mobile-nav{margin-left:1.6rem}}@media screen and (max-width:599px){#bloglo-header-inner .bloglo-widget-wrapper,.bloglo-header-element,.bloglo-header-widgets .bloglo-header-widget{position:static}.bloglo-header-widgets .dropdown-item:after{display:none}}@media screen and (max-width:480px){#page{min-height:-webkit-fill-available}}@media screen and (max-width:960px){#main>.bloglo-container{display:block}#primary{max-width:100%!important;padding-left:0!important;padding-right:0!important;margin-top:4rem}}@media all and (-ms-high-contrast:none),(-ms-high-contrast:active){#main>.bloglo-container #primary{-ms-flex-preferred-size:0%;flex-basis:0%}}.single .post-category a{color:var(--bloglo-primary)}.single .post-category a{border-color:var(--bloglo-primary)}#masthead .bloglo-header-widgets .dropdown-item:after{border-bottom-color:var(--bloglo-primary);outline:none!important}.bloglo-header-widgets .dropdown-item{border-top-color:var(--bloglo-primary)}::-webkit-selection{background-color:var(--bloglo-primary);color:var(--bloglo-white)}*{scrollbar-width:thin;scrollbar-color:rgba(0,0,0,.2) transparent}::-webkit-scrollbar{width:.7rem;height:.7rem}::-webkit-scrollbar-track{background:0 0}::-webkit-scrollbar-thumb{background:rgba(0,0,0,.2)}::-webkit-scrollbar-thumb:hover{background:rgba(0,0,0,.4)}@media (prefers-reduced-motion:reduce){*{animation-duration:0s!important}}.bloglo-cursor{visibility:hidden;position:fixed;z-index:10000;display:flex;justify-content:center;align-items:center;top:0;left:0}.bloglo-cursor .bloglo-cursor-wrapper{display:flex;justify-content:center;align-items:center}.bloglo-cursor .bloglo-cursor--follower{position:absolute;background-color:var(--bloglo-primary);opacity:.35;border-radius:100%;width:2.4rem;height:2.4rem}.bloglo-cursor .bloglo-cursor--label{position:absolute;display:flex;justify-content:center;align-items:center;color:var(--bloglo-white);letter-spacing:.08em;transform:scale(0);will-change:transform,opacity}.bloglo-cursor .bloglo-cursor--icon{position:absolute;display:flex;justify-content:center;align-items:center;color:var(--bloglo-white);transform:scale(0);will-change:transform,opacity;color:rgba(255,255,255,.76)}.bloglo-cursor .bloglo-cursor--icon:before{content:"\f061";font-family:var(--bloglo-font-awesome);font-size:2.4rem}:root{--bloglo-primary:#f24d4d;--bloglo-primary_15:#f46868;--bloglo-primary_27:rgba(242,77,77,.27);--bloglo-primary_09:rgba(242,77,77,.09);--bloglo-primary_04:rgba(242,77,77,.04)}#bloglo-header-inner{background:#fff}#bloglo-header,.bloglo-header-widgets a:not(.bloglo-btn),.bloglo-logo a,.bloglo-hamburger{color:#131315}#bloglo-header-inner{border-color:rgba(39,39,39,.75)}.bloglo-header-widget:after{background-color:#ccc}@media screen and (max-width:1024px){#bloglo-header-inner .bloglo-nav{display:none;color:#000}.bloglo-mobile-nav{display:inline-flex}#bloglo-header-inner{position:relative}#bloglo-header-inner .site-navigation{display:none;position:absolute;top:100%;width:100%;height:100%;min-height:100vh;left:0;right:0;margin:-1px 0 0;background:#fff;border-top:1px solid #eaeaea;box-shadow:0 15px 25px -10px rgba(50,52,54,.125);z-index:999;font-size:1.7rem;padding:0}}.bloglo-nav.bloglo-header-element,.bloglo-header-layout-2 .bloglo-header-widgets{font-size:1.6rem}body{color:#131315}:root{--bloglo-secondary_38:#131315}.entry-meta{color:#131315}.entry-meta .entry-meta-elements>span:before{background-color:}h1{color:#333}:root{--bloglo-secondary:#333}.bloglo-container{max-width:1420px}.bloglo-logo img{max-height:45px}.bloglo-logo .logo-inner{margin-top:25px;margin-right:25px;margin-bottom:25px}@media only screen and (max-width:768px){.bloglo-logo .logo-inner{margin-top:25px;margin-right:1px;margin-bottom:25px}}.bloglo-breadcrumbs{padding-top:15px;padding-bottom:15px}.bloglo-breadcrumbs{background:#fff9f3}.bloglo-breadcrumbs{border-color:#ffe7d2;border-style:solid;border-top-width:1px;border-bottom-width:1px}html{font-size:62.5%}@media only screen and (max-width:768px){html{font-size:53%}}@media only screen and (max-width:480px){html{font-size:50%}}*{-moz-osx-font-smoothing:grayscale;-webkit-font-smoothing:antialiased}body{font-weight:400;font-family:"Be Vietnam Pro",Helvetica,Arial,sans-serif;font-size:1.7rem;line-height:1.75}h1{font-weight:700;font-style:normal;text-transform:none;text-decoration:none}h1{font-weight:700;font-size:4rem;line-height:1.1}span.bloglo-header-element.bloglo-mobile-nav{display:none}:root{--wpforms-field-border-radius:3px;--wpforms-field-background-color:#fff;--wpforms-field-border-color:rgba(0,0,0,.25);--wpforms-field-text-color:rgba(0,0,0,.7);--wpforms-label-color:rgba(0,0,0,.85);--wpforms-label-sublabel-color:rgba(0,0,0,.55);--wpforms-label-error-color:#d63637;--wpforms-button-border-radius:3px;--wpforms-button-background-color:#066aab;--wpforms-button-text-color:#fff;--wpforms-page-break-color:#066aab;--wpforms-field-size-input-height:43px;--wpforms-field-size-input-spacing:15px;--wpforms-field-size-font-size:16px;--wpforms-field-size-line-height:19px;--wpforms-field-size-padding-h:14px;--wpforms-field-size-checkbox-size:16px;--wpforms-field-size-sublabel-spacing:5px;--wpforms-field-size-icon-size:1;--wpforms-label-size-font-size:16px;--wpforms-label-size-line-height:19px;--wpforms-label-size-sublabel-font-size:14px;--wpforms-label-size-sublabel-line-height:17px;--wpforms-button-size-font-size:17px;--wpforms-button-size-height:41px;--wpforms-button-size-padding-h:15px;--wpforms-button-size-margin-top:10px}:root{--ss-fsidebar-spacing:0px}.ss-popup-overlay .ss-copy-action .ss-button,.ss-popup-overlay .ss-popup .ss-close-modal,.ss-popup-overlay .ss-popup .ss-popup-networks .ss-popup-network>a{border:0;text-shadow:none;-webkit-box-shadow:none;box-shadow:none;outline:0;text-decoration:none;text-transform:none;letter-spacing:0}.ss-svg-icon{height:16px;width:auto;vertical-align:text-bottom;fill:currentColor}.ss-envelope-color{background-color:#323b43}.ss-facebook-color{background-color:#1877f2}.ss-twitter-color{background-color:#000}.ss-linkedin-color{background-color:#2867b2}.ss-copy-color{background-color:#323b43}.ss-print-color{background-color:#323b43}.ss-mix-color{background-color:#ff8226}.ss-clearfix:after{content:"";display:table;clear:both}:root{--ss-wpadminbar-height:0px}.ss-popup-overlay{display:none;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,Arial,"Helvetica Neue",sans-serif;-webkit-font-smoothing:initial;content:"";position:fixed;top:0;bottom:0;left:0;right:0;z-index:99999;background:rgba(202,202,202,.75);opacity:0}.ss-popup-overlay .ss-copy-action{position:relative;display:none}.ss-popup-overlay .ss-copy-action .ss-copy-action-field{border:1px solid rgba(0,0,0,.1);border-radius:2px;color:#323b43;font-family:inherit;font-size:16px;-webkit-box-sizing:border-box;box-sizing:border-box;width:100%;height:48px!important;line-height:48px!important;padding:0 120px 0 50px!important;text-shadow:none;-webkit-box-shadow:none;box-shadow:none;outline:0;background-color:#fff;margin:0}.ss-popup-overlay .ss-copy-action .ss-button{font-weight:400;font-family:inherit;position:absolute;right:6px;top:5px;background-color:#557ceb;color:#fff;padding:0;line-height:38px;height:38px;width:105px;font-size:16px;z-index:9;border-radius:2px}.ss-popup-overlay .ss-copy-action svg{position:absolute;height:24px;width:24px;top:50%;left:15px;margin-top:-12px;fill:#dadada}.ss-popup-overlay .ss-popup{opacity:0;border-radius:2px;max-width:90%;max-height:90%;width:720px;height:auto}.ss-popup-overlay .ss-popup .ss-popup-heading{display:block;display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-align:center;-ms-flex-align:center;align-items:center;font-size:16px;font-weight:300;color:#323b43;background-color:#fff;line-height:58px;height:58px;padding:0 0 0 24px;margin:0;border-top-left-radius:4px;border-top-right-radius:4px}.ss-popup-overlay .ss-popup .ss-close-modal{margin-left:auto;padding:0 24px;height:100%;display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-align:center;-ms-flex-align:center;align-items:center;color:#a9a9a9}.ss-popup-overlay .ss-popup .ss-close-modal svg{width:16px;height:16px}.ss-popup-overlay .ss-popup .ss-popup-content{position:relative;top:3px;left:0;right:0;bottom:0;max-height:70vh;background-color:#fff;overflow-y:scroll;padding:24px 24px 20px;border-bottom-left-radius:4px;border-bottom-right-radius:4px}.ss-popup-overlay .ss-popup .ss-popup-networks{display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-orient:horizontal;-webkit-box-direction:normal;-ms-flex-direction:row;flex-direction:row;-ms-flex-wrap:wrap;flex-wrap:wrap;margin:0 -6px}.ss-popup-overlay .ss-popup .ss-popup-networks .ss-popup-network{-webkit-box-sizing:border-box;box-sizing:border-box;width:33.33%;padding:0 6px 6px;-ms-flex-negative:0;flex-shrink:0;float:left;display:inline-block}.ss-popup-overlay .ss-popup .ss-popup-networks .ss-popup-network>a{position:relative;-webkit-box-sizing:border-box;box-sizing:border-box;height:40px;padding:0 15px 0 0;display:-webkit-box;display:-ms-flexbox;display:flex;line-height:40px;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-orient:horizontal;-webkit-box-direction:normal;-ms-flex-direction:row;flex-direction:row;color:#fff;border-radius:2px;font-weight:500;font-size:13px;vertical-align:middle;-webkit-backface-visibility:hidden;white-space:nowrap;text-overflow:ellipsis}.ss-popup-overlay .ss-popup .ss-popup-networks .ss-popup-network>a span:first-child{position:relative;z-index:2;height:40px;width:40px;text-align:center;line-height:40px;font-size:16px;margin-right:10px;background-color:rgba(0,0,0,.15);display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-align:center;-ms-flex-align:center;align-items:center}.ss-popup-overlay .ss-popup .ss-popup-networks .ss-popup-network>a svg{fill:#fff;height:16px;width:inherit;z-index:1}.ss-popup-overlay .ss-popup .ss-popup-networks .ss-popup-network>a span:first-child:before{content:"";position:absolute;left:0;top:0;background-color:rgba(0,0,0,.1)}.ss-popup-overlay .ss-popup .ss-popup-networks .ss-popup-network>a span{position:relative;z-index:3}.ss-popup-overlay .ss-popup .ss-popup-networks .ss-popup-network>a:before{position:absolute;content:"";background-color:rgba(255,255,255,0);top:0;left:0;bottom:0;right:0;z-index:1}.ss-share-network-tooltip{font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,Arial,"Helvetica Neue",sans-serif;-webkit-font-smoothing:initial;position:absolute;line-height:1;left:100%;margin-left:12px;background-color:rgba(56,70,84,.85);top:50%;width:auto;white-space:nowrap;padding:8px 10px;border-radius:2px;font-size:12px;color:rgba(255,255,255,.9);z-index:2;opacity:0;-webkit-transform:translateX(-7px) translateY(-50%);-ms-transform:translateX(-7px) translateY(-50%);transform:translateX(-7px) translateY(-50%)}.ss-copy-action .ss-share-network-tooltip{left:auto;margin-left:0;right:100%;margin-right:12px;-webkit-transform:translateX(7px) translateY(-50%);-ms-transform:translateX(7px) translateY(-50%);transform:translateX(7px) translateY(-50%)}@media screen and (max-width:782px){.ss-popup-overlay .ss-popup .ss-popup-networks .ss-popup-network{width:50%}}@media screen and (max-width:500px){.ss-popup-overlay .ss-popup .ss-popup-networks .ss-popup-network{width:100%}}
Launching Your React App on Kubernetes: A Step-by-Step Guide – Finally Ahead
Skip to content Home Programming Launching Your React App on Kubernetes: A Step-by-Step Guide Deploying applications in the modern world of cloud computing can be complex, but tools like Docker, Kubernetes, and Minikube have made it much simpler and more efficient. This step-by-step guide will walk you through containerizing your React application with Docker and deploying it on a Kubernetes cluster using Minikube and kubectl. By the end of this tutorial, you’ll have a solid foundation on how to take your React application from development to a scalable production environment.
Setting Up Your React Application First things first, let’s set up our project directory and create a React application using Create React App.
mkdir my-k8s-project && cd my-k8s-project
mkdir K8s && mkdir react-docker
cd react-docker
npx create-react-app .
To test your application locally, you can simply run npm start
, and your app should be available at http://localhost:3000/
.
Remember, you can change the default port by adding a .env
file and setting a different port, like so:
PORT=3002
Once you’re happy with your development build, compile your app for production:
This command will output static files to a build
directory, ready to be served.
Dockerizing Your React Application Before you dockerize your application, ensure you have a Docker account and are logged in. Create a Dockerfile
and .dockerignore
in your project’s root directory to define how your Docker image should be built.
Dockerfile:
FROM nginx:alpine
COPY build /usr/share/nginx/html
.dockerignore:
node_modules
.git
Dockerfile
.dockerignore
Build your Docker image with the following command:
docker build -t your_docker_username/react-docker .
Then, run your containerized application to ensure everything works as expected:
docker run -d -p 3000:80 your_docker_username/react-docker
Your app should now be accessible at http://localhost:3000/
. Don’t forget to push your image to Docker Hub for deployment:
docker push your_docker_username/react-docker
Deploying to Kubernetes with Minikube Start by setting up a local Kubernetes cluster with Minikube and switch to the newly created namespace:
minikube start
kubectl create namespace react-docker
kubectl config set-context --current --namespace=react-docker
Create a deployment.yaml
to specify your deployment configuration:
apiVersion: apps/v1
kind: Deployment
metadata:
name: react-docker
spec:
replicas: 2
selector:
matchLabels:
app: react-docker
template:
metadata:
labels:
app: react-docker
spec:
containers:
- name: react-docker
image: your_docker_username/react-docker
ports:
- containerPort: 80
Deploy your application to the Kubernetes cluster:
kubectl apply -f deployment.yaml
To make your application accessible, create a service with a load-balancer.yaml
and apply it:
#load-balancer.yaml
apiVersion: v1
kind: Service
metadata:
name: load-balancer
spec:
type: LoadBalancer
ports:
- port: 80
nodePort: 31000
targetPort: 80
selector:
app: react-docker
kubectl apply -f load-balancer.yaml
Find the Minikube IP with minikube ip
and access your app at http://<minikube-ip>:31000/
.
Scaling up and down is straightforward with kubectl:
kubectl scale deployment/react-docker --replicas=10 # Scaling up
kubectl scale deployment/react-docker --replicas=3 # Scaling down
Conclusion By following these steps, you’ve learned how to take a React application, containerize it with Docker, and deploy it on a Kubernetes cluster using Minikube. This workflow demonstrates the power of containerization and orchestration for managing and scaling web applications efficiently.
Remember, this is just the beginning. Both Kubernetes and Docker offer a wealth of features and options to support more complex deployment scenarios and workflows. Happy deploying!
Scroll to Top