Skip to content

Instantly share code, notes, and snippets.

@YannMjl
Last active August 10, 2021 21:12
Show Gist options
  • Save YannMjl/db9ab39f4d511cc1eaab22d120722b3e to your computer and use it in GitHub Desktop.
Save YannMjl/db9ab39f4d511cc1eaab22d120722b3e to your computer and use it in GitHub Desktop.
This is the kubernetes deployment yaml file for nodejs demo app
# check out all Kubernetes commands here:
# https://kubernetes.io/docs/reference/kubectl/cheatsheet/
# -----------------------------------------------------------*
# implies the use of kubernetes 1.7
# use apps/v1beta2 for kubernetes 1.8
# -----------------------------------------------------------*
apiVersion: apps/v1
kind: Deployment
metadata:
name: nodej-demo-app
namespace: default
spec:
replicas: 4 # this is number of pods
selector:
matchLabels:
app: nodejs-demo-app
template:
metadata:
labels:
app: nodejs-demo-app
spec:
# Kubernetes run docker pull pseudo/your-image:latest under the hood
# Image field in Kubernetes resources is simply the docker image to run.
containers:
- name: nodejs-demo-app
# pulling image from my DockerHub
image: yanndocker/nodejs-demo:latest
# using if not present works well with images that has tag
# if you image is tag:lastest - use Always otherwise you
# wouldn't get the fresh version of your image
imagePullPolicy: Always
# -----------------------------------------------------------*
# It is a good practice to declare resource requests and
# limits for both memory and cpu for each container.
# This helps to schedule the container to a node that has
# available resources for your Pod, and also so that your
# Pod does not use resources that other Pods needs
# -----------------------------------------------------------*
resources:
limits:
memory: 64Mi
cpu: "250m"
requests:
memory: 32Mi
cpu: "200m"
# specify the container port
ports:
- containerPort: 30002
# -----------------------------------------------------------*
# If your image is hosted in a private docker hub repo,
# you need to specify an image pull secret in the spec field.
# -----------------------------------------------------------*
# spec:
# containers:
# - name: app
# image: pseudo/your-image:latest
# imagePullSecrets:
# - name: dockerhub-credential
# -----------------------------------------------------------*
---
apiVersion: v1
kind: Service
metadata:
name: nodejs-demo-app-entrypoint
namespace: default
spec:
# -----------------------------------------------------------*
# if you're using service type NodePort. To access you app
# and test it locally you need to listen on local port.
# you can do that by forwarding a local port to Service target
# port with name <my-service-name>
# e.g --
# kubectl port-forward service/nodejs-demo-app-entrypoint 3000:443
# -----------------------------------------------------------*
# type: NodePort
type: LoadBalancer
selector:
app: nodejs-demo-app
# The range of valid ports in kubernetes is 30000-32767
ports:
- name: http
protocol: TCP
port: 80 # this is service port 80
targetPort: 30002
# nodePort: 30003 # this is for when using type: NodePort
- name: https
protocol: TCP
port: 443 # this is service port 443
targetPort: 30002
# nodePort: 30004 # this is for when using type: NodePort
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment