1.0.26 • Published 1 year ago
@dgpholdings/backend-mono v1.0.26
Development setup
We will need the following
- Docker installed in local system for containerization. Use
docker versionto check installation - Kubernetes Installed through Docker GUI to use the docker container for deployment. User
kubectl versionto check installation. - ingress-nginx installed which acts as a bridge between Kubernetes cluster and outside world + load balancing + routing configuration.
- We need to update our system
hostsfile with an entry127.0.0.1 ensloka.dev. For MacOs/etc/hostsand for Windows:C:\Windows\System32\Drivers\etc\hosts
Start Server
- In terminal from the project root-
skaffold devornpm run dev - Now you can access
https://ensloka.dev/api-authentication/pingIf youre blocked due to certificate, you try by clicking anywhere on the browser tab and typethisisunsafe
Npm package @dgpholdings/backend-mono
This package returns typescript types for the front-end app to use the api contracts
To publish update:
- Commit all changes in the repo
npm run pub
Docker basic usage
docker build -t <docker-userId>/<service-name> .Note the . dot in th end is imp to build an imagedocker push <docker-userId>/<service-name>next push the image to DockerHub, for the k8s deployment to pull down this image for creating a pod.
Some handy Kubernetes commands
kubectl apply -f some.ymlthis will run any yml script for kuberneteskubectl get servicesto list running serviceskubectl get podsto list running podskubectl describe pod <name>describes a podkubectl delete svc <name>to delete a servicekubectl exec -it <pod-name> shto get inside the file system of a podkubectl port-forward <pod-name> 8001:8001to quickly expose a running pod (in k8s cluster) listening on port8001to the outside world
Setting ENVIRONMENT_VARIABLE in Kubernetes
- Example:
kubectl create secret generic <object-name-ref> --from-literal=NODE_ENV=development --from-literal=COUNTRY=de- There are other ways and options to set environment variables too
- In our app we are setting env variable through
- First an entry in
.dev.envfile and then - In
server-depl.yamlfile the same env entries inenv:scope
- First an entry in
- Then we can do
kubectl get secretsto list all the secret objects in the cluster - Now in the
*-depl.yamlfile of the pod where we want to access the environment variable and fo the following
...
spec:
containers:
- name: auth
image: austin4silvers/auth
env: ## <== here we are making new entry
- name: NODE_ENV
valueFrom:
secretKeyRef:
name: <the-object-name-ref>
key: NODE_ENVSteps to update an image used by a deployment (for PRODUCTION)
- Create a
depl-someservice.ymland make sure we are using :latest tag by default in the pod spec section of the yml file (when specifying theimage: austin4silvers/auth) - Make an update to your code in the service
- Build the image of the service
- Push image to the DockerHub
- run
kubectl rollout restart deployment <deployment_name>
Steps to update an image used by a deployment (for DEVELOPMENT) using "Skaffold"
Using Skaffold because. (~/skaffold.yml houses the configuration)
- It will watch for changes in
/infra/*directory for changes, then it will automatically apply to our k8s cluster - It will watch for any changes in any our services code, and then sync the changes with their respective containers running inside the cluster
skaffold dev // from the root of the project to start skaffold
kubectl get pods // to check if all the deployed pods are "Running" (in a different terminal)Development Notes
- To emit any error as response, use Error classes that extends
BaseError. For example:throw new ErrorGeneral("...)is ✅. Butthrow new Error("..)is ❌.
Troubleshooting:
- For error:
{"errorMessage": ""}, check your request body, its probably an invalid json.
1.0.26
1 year ago
1.0.25
1 year ago
1.0.23
1 year ago
1.0.22
1 year ago
1.0.21
1 year ago
1.0.20
1 year ago
1.0.19
1 year ago
1.0.18
1 year ago
1.0.17
1 year ago
1.0.16
1 year ago
1.0.15
1 year ago
1.0.14
1 year ago
1.0.13
1 year ago
1.0.12
1 year ago
1.0.10
1 year ago
1.0.9
1 year ago
1.0.5
1 year ago
1.0.4
1 year ago
1.0.3
1 year ago
1.0.2
1 year ago
1.0.1
1 year ago
1.0.0
1 year ago