Giter Club home page Giter Club logo

ibm / deploy-react-kubernetes Goto Github PK

View Code? Open in Web Editor NEW
141.0 23.0 108.0 1.52 MB

Built for developers who are interested in learning how to deploy a React application on Kubernetes, this pattern uses the React and Redux framework and calls the OMDb API to look up movie information based on user input. This pattern can be built and run on both Docker and Kubernetes.

Home Page: https://developer.ibm.com/code/patterns/deploy-a-react-application-on-kubernetes/

License: Apache License 2.0

HTML 3.14% JavaScript 77.23% CSS 18.56% Dockerfile 1.08%
ibmcode kubernetes kubernetes-cluster omdb-api ibm-cloud docker react redux

deploy-react-kubernetes's Introduction

Build Status

Deploy a React application on Kubernetes

Do you have a front end application that contains large amounts of duplication, handles complex states, and manages large amounts of data?

React and Redux is the perfect Javascript library if your application is similar to the one described above. React provides a component based structure for everything included in an application and allows abstraction if needed to limit duplication. With Redux, it handles all of the state and can easily manage data in an application.

Once an application has been developed, it needs to be deployed for the rest of the world to see. There are many choices when looking for the right solution to manage and deploy your application. It can often be overwhelming when you're trying to pick the right solution.

If you're looking for a deployment tool that can provide automation, scalability and management of a deployed application, Kubernetes is the tool for you!

An application must be packaged into a container to deploy on Kubernetes. Docker is an open source tool that is used to package the application into a container. The container is then deployed on Kubernetes for public access. Once the application is deployed, Kubernetes handles the management, scalability and automation of the deployed application.

In this Code Pattern, we will deploy a React application using Kubernetes.

This repository uses the React Javascript library alongside Redux to build out the front end of the application. The OMDb API is used to get movie information based on user input. Redux handles the data between the application and the API, as well as the state between components. Docker is used to package the application and Kubernetes is used to deploy the container.

When the reader has completed this Code Pattern, they will understand how to:

  • Containerize a React application using Docker
  • Deploy and manage an application using Kubernetes

Flow

Flow

  1. The user accesses the application through the web interface. The user enters a movie title into the input.
  2. The React application is rendered to the user on access.
  3. The application calls the OMDb API and receives a JSON object of the response to show the user.

Included components

  • IBM Cloud Container Service: IBM Cloud Container Service manages highly available apps inside Docker containers and Kubernetes clusters on the IBM Cloud.
  • Kubernetes Cluster: Create and manage your own cloud infrastructure and use Kubernetes as your container orchestration engine.

Featured technologies

  • Node.js: An open-source JavaScript run-time environment for executing server-side JavaScript code.
  • Cloud: Accessing computer and information technology resources through the Internet.
  • Container Orchestration: Automating the deployment, scaling and management of containerized applications.

Watch the video

Steps

Prerequisites

  1. You must get an API key from OMDb API in order to get a response from the API. You will insert your API key in /src/actions/index.js on line 42 OMDb API by Brian Fitz is licensed under CC BY-NC 4.0

  2. Create an environment variable for your docker username

$ export docker_username="YOUR_DOCKER_USERNAME"

Run locally

  1. Clone the repo
  2. Run the application

1. Clone the repo

Clone the repo locally. In a terminal, run:

$ git clone https://github.com/IBM/deploy-react-kubernetes

2. Run the application

  1. Install Node.js
  2. Run the following commands in a terminal:
$ npm install

$ npm run build-css

$ npm run start

Verify app is running and working correctly.

Run the application using Docker

  1. Build the image
  2. Run the image

Prerequisites:

  1. Create Docker account

  2. Install Docker CLI

  3. Retrieve and save your Docker user id

1. Build the image

In a terminal, run:

$ docker build -t $docker_username/deploy-react-kubernetes .

Your image should be listed by running:

$ docker images

2. Run the image

In a terminal, run:

$ docker run -p 3000:3000 -d $docker_username/deploy-react-kubernetes

You can now access the application at http://localhost:3000

Run the application on Kubernetes

  1. Build image.
  2. Deploy the application

Prerequisites

  1. Create an account with IBM Cloud

  2. Install IBM Cloud CLI

  3. Log into your IBM Cloud account

ibmcloud login

If you have a federated ID, use ibmcloud login --sso to log in to the IBM Cloud CLI.

  1. Install the Container Registry plug-in.
ibmcloud plugin install container-registry -r Bluemix
  1. Install the Container Service plug-in.
ibmcloud plugin install IBM-Containers -r Bluemix
  1. Install kubectl

  2. Create cluster

ibmcloud cs cluster-create --name YOUR_CLUSTER_NAME
  1. Configure Kubernetes cluster
$ ibmcloud cs cluster-config YOUR_CLUSTER_NAME

Copy and paste response in CLI

  1. Choose a name for your first namespace, and create that namespace. Use this namespace for the rest of the Quick Start.
$ ibmcloud cr namespace-add YOUR_NAMESPACE

1. Build image

Build image in the IBM Container Registry:

$ ibmcloud cr build -t registry.<ibm_cloud_region>.bluemix.net/<your_namespace>/deploy-react-kubernetes .

2. Deploy the application

$ kubectl run deploy-react-kubernetes-deployment --image=registry.<ibm_cloud_region>.bluemix.net/<your_namespace>/deploy-react-kubernetes

To check how many pods are running on Kubernetes run the command:

kubectl get pods

Expose the app to the web by setting the port. Run the command:

$ kubectl expose deployment/deploy-react-kubernetes-deployment —-port=3000 —-type=NodePort
  • To access your application. You would need the public IP address of your cluster and NodePort of the service.
# For clusters provisioned with IBM Cloud
$ ibmcloud cs workers YOUR_CLUSTER_NAME
# For details on a specific Kubernetes service
$ kubectl describe service deploy-react-kubernetes-service

You can now access the application at http://IP_ADDRESS:NODE_PORT

Run the application on Kubernetes with a yaml file

Note: Follow the prerequisites in 'Run the application on Kubernetes section' before executing command below.

kubectl create -f deployment.yaml

Sample output

screen shot 2017-03-13 at 6 14 10 pm

Links

Learn more

License

This code pattern is licensed under the Apache Software License, Version 2. Separate third party code objects invoked within this code pattern are licensed by their respective providers pursuant to their own separate licenses. Contributions are subject to the Developer Certificate of Origin, Version 1.1 (DCO) and the Apache Software License, Version 2.

Apache Software License (ASL) FAQ

deploy-react-kubernetes's People

Contributors

anthonyamanse avatar dependabot[bot] avatar dolph avatar jmz7v avatar jzaccone avatar kant avatar ljbennett62 avatar mofsal avatar stevemar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

deploy-react-kubernetes's Issues

Add more testing

There's unit testing but we should add more tests:

  • Container functions
  • Action dispatch (API call)
  • Accessibility
  • Performance

Add docs for IBM Cloud steps

Add screenshots of how to provision Kubernetes in the UI and any prerequisites like Docker account, IBM account, etc

Add docs for deploying with yaml

Right now in the README.md, it just has cli commands to deploy. I've added a yaml deployment file so docs should be added how to deploy with that

kubectl create -f deployment.yaml

Update IBM Cloud docs

Below is a list of steps that I followed to deploy the React app to Kubernetes. There was quite a bit to install to get things working. I had to install Docker, Node.js and the IBM CLIs. The https://github.com/IBM/container-service-getting-started-wt/tree/master/Lab%201 helped me to configure the cluster. The README.md docs on https://github.com/IBM/deploy-react-kubernetes needs to be updated with some of the steps below.

Step 0:

Create an account with IBM Bluemix at https://console.bluemix.net/registration/

Step 1:

You must get an API key from OMDb API in order to get a response from the API. You will insert your API key in /src/actions/index.js on line 42 OMDb API by Brian Fitz is licensed under CC BY-NC 4.0

Create an environment variable for your docker username
$ export docker_username="YOUR_DOCKER_USERNAME"

Step 2:
Clone the repo locally. In a terminal, run:
$ git clone https://github.com/IBM/deploy-react-kubernetes

Step 3:
Run the application

Install Node.js
Run the following commands in a terminal:

$ npm install

$ npm run build-css

$ npm run start

Verify app is running and working correctly.

Step 4:

Get the Docker User Id.

https://cloud.docker.com/

Save your Docker User Id.

Install Docker

https://www.docker.com/community-edition

Step 5:
Run the application using Docker

Build the image
Run the image
  1. Build the image
    In a terminal, run:
    $ docker build -t <your_namespace>/deploy-react-kubernetes .
    Your image should be listed by running:
    $ docker images
  2. Run the image
    In a terminal, run:
    $ docker run -p 3000:3000 -d <your_namespace>/deploy-react-kubernetes

You can now access the application at http://localhost:3000

Step 6:
Run the application on Kubernetes
Go to : https://console.bluemix.net/containers-kubernetes/registry/start

Install, Set Up, and Log In

  1. Install the IBM Cloud CLI.
  2. Install the Docker CLI.
  3. Install the Container Registry plug-in.
    bx plugin install container-registry -r Bluemix
  4. Log in to your IBM Cloud account.
    bx login -a https://api.au-syd.bluemix.net
    If you have a federated ID, use bx login --sso to log in to the IBM Cloud CLI.
  5. Choose a name for your first namespace, and create that namespace. Use this namespace for the rest of the Quick Start.
    bx cr namespace-add

To list namespaces use command: bx cr namespaces

Step 7:
Build the Docker Image

bx cr build -t registry.au-syd.bluemix.net/<your_namespace>/deploy-react-kubernetes .

To view the Docker Image run the command: docker images

Step 8:
Deploy the app to Kubernetes

To create a cluster run command: bx cs cluster-create --name mycluster

This will take 5 minutes so in the meantime run: bx cs workers mycluster

OK
ID Public IP Private IP Machine Type State Status Zone Version
kube-mel01-pa055d203a2cc4451da75e187339112542-w1 168.1.145.167 10.118.181.226 free provisioning Waiting for master to be deployed mel01 1.8.11_1509

Step 9:
Configure Kubernetes cluster
Once the cluster is active run the command: bx cs cluster-config mycluster

You should get a response like:

OK
The configuration for mycluster was downloaded successfully. Export environment variables to start using Kubernetes.

export KUBECONFIG=/Users//.bluemix/plugins/container-service/clusters/mycluster/kube-config-mel01-mycluster.yml

Then run the command to set the env variable: export KUBECONFIG=/Users//.bluemix/plugins/container-service/clusters/mycluster/kube-config-mel01-mycluster.yml

Step 10:
Run the app in Kubernetes

kubectl run deploy-react-kubernetes-deployment --image**=**registry.au-syd.bluemix.net/<your_namespace>/deploy-react-kubernetes

To check how many pods are running on Kubernetes run the command: kubectl get pods
Expose the app to the web by setting the port. Run the command:

kubectl expose deployment/deploy-react-kubernetes-deployment --type="NodePort" --port=3000

Find the public IP address of Kubernetes:

bx cs workers mycluster

kubectl get services

Check the app is deployed, go to IP address:3000.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.