---
# System prepended metadata

title: React on k8s
tags: [learn]

---

---
tags: learn
---

# React on k8s

## Running a simple react app on a azure k8s cluster


### Create the app:

```shell
npx create-react-app frontend --template typescript
```

### Containerise the app

- Put in Dockerfile with contents in the frontend folder and use a Makefile to push to private container registry in gitlab.

- Put in node modules in `.dockerignore` as we don't need to add it to the docker build container step. 
  - `make push` to put it on gitlab registry
  - You need to login to gitlab using a token. To generate a token go to "User settings" and click on "Access token". Create a personal token checking read and write registry. Copy the token and store it. To login: docker login registry.gitlab.com -u <username> -p <token>
  - Access tokens are when you want to login as yourself. Deploy tokens are used when you use an automated step and Computer X is doing it.
  
### Create deploy token on gitlab and generate secrets
  - To create a deploy token go to Settings->Repository-> Deploy token
  - Choose read_registry under scopes
  - Put the deploy token in `generate_secret.sh` 
  - Make sure that secret is applied using `apply_secret.sh`
  - Check in `k9s` secrets to see if it is applied
  - Information for creating a kubernetes secret that allows pulling of the private image: https://github.com/docker/for-mac/issues/4100#issuecomment-648977556
  
### Create manifest (imperative for production)
 - Create 'deployment.yaml' and link it to app registry
 - Add imagePullsecrets under spec 'deployment.yaml'



