Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ezeparziale/nextjs-k8s
:whale: Next.js app with 2 pods sharing cache on redis
https://github.com/ezeparziale/nextjs-k8s
cache docker docker-compose kubernetes nextjs pod redis standalone vps
Last synced: 2 days ago
JSON representation
:whale: Next.js app with 2 pods sharing cache on redis
- Host: GitHub
- URL: https://github.com/ezeparziale/nextjs-k8s
- Owner: ezeparziale
- Created: 2023-11-19T18:20:12.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-01-25T00:22:34.000Z (28 days ago)
- Last Synced: 2025-02-12T17:13:59.059Z (9 days ago)
- Topics: cache, docker, docker-compose, kubernetes, nextjs, pod, redis, standalone, vps
- Language: TypeScript
- Homepage:
- Size: 495 KB
- Stars: 126
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# :zap: Next.js 14 + Redis cache + Kubernetes
Next.js web application with 2 pods sharing cache on Redis.
## :speech_balloon: About this repo
### :whale: Docker
I created the Docker image following the example in:
```http
https://github.com/vercel/next.js/tree/canary/examples/with-docker
```I configured the `output: "standalone"` property in `next-config.mjs`.
More info at:
```http
https://nextjs.org/docs/app/building-your-application/deploying#docker-image
```### :card_file_box: Cache
I use `Redis` to cache values and ensure consistency across all pods.
I installed `@neshca/cache-handler` using `npm i -D @neshca/cache-handler`:
```http
https://caching-tools.github.io/next-shared-cache
```I added `cache-handler.mjs` and configured the `cacheHandler` property in
`next.config.mjs`.I followed this example and the same pages to validate the cache using `revalidateTag`
and `revalidatePath`:```http
https://github.com/vercel/next.js/tree/canary/examples/cache-handler-redis
```More info at:
```http
https://nextjs.org/docs/app/building-your-application/deploying#caching-and-isr
```### :camera_flash: Image optimization
I installed `sharp` using `npm install sharp`.
More info at:
```http
https://nextjs.org/docs/app/building-your-application/deploying#image-optimization
```### :whale2: Kubernetes
In the `k8s` folder, there are all the `Kubernetes` manifests to create two pods with
the Next.js web application and one pod with a Redis server.## :runner: Run
### :1st_place_medal: Option 1
Run in dev mode with `npm run dev`.
### :2nd_place_medal: Option 2
Run in Docker using Docker Compose with
`docker compose -f "compose.yaml" up -d --build`.### :3rd_place_medal: Option 3
Run in Kubernetes:
1. Execute `docker build -t nextjs-docker .` to create the Docker image.
2. Execute `kubectl apply -f k8s/configmaps/nextjs.yaml`.
3. Execute `kubectl apply -f k8s/deployments/nextjs.yaml`.
4. Execute `kubectl apply -f k8s/deployments/redis.yaml`.
5. Execute `kubectl apply -f k8s/services/nextjs.yaml`.
6. Execute `kubectl apply -f k8s/services/redis.yaml`.
7. Access `http://localhost:3000`.> [!NOTE]
> You can use this option to deploy your Docker image on your VPS.