K8s Node Development 02/14/23
- Remove
livenessProbe
and readinessProbe
- Modify the deployment's
spec.containers[0]
to the following:
command: ["node", "--inspect=0.0.0.0:9229", "index.js"]
- Enable debugging in the service by exposing the chosen debug port (this example uses the default 9229):
ports:
- containerPort: 80
name: http
protocol: TCP
- containerPort: 9229
name: debug
protocol: TCP
- Put newly created pod name in a variable:
pod=$(k get pods --selector app.kubernetes.io/name=$1 -o json | jq -r '.items[0].metadata.name')
- Shell into the newly created pod:
k -n gval exec -it $pod -- /bin/bash
apt update && apt install -y rsync procps entr
- Run
entr
to monitor for changes on the repository and restart the Node server:
find . -not -path '*node_modules*' -not -path '*.git*' -not -path '*test*' | entr -r node public-api.js 1>> /proc/1/fd/1 2>> /proc/1/fd/2 &
- Now you can run
rsync
on your development machine to copy files to the container (see this SO question):
#!/bin/bash
if [ -z "$KRSYNC_STARTED" ]; then
export KRSYNC_STARTED=true
exec rsync --blocking-io --rsh "$0" $@
fi
# Running as --rsh
namespace=''
pod=$1
shift
# If use uses pod@namespace rsync passes as: {us} -l pod namespace ...
if [ "X$pod" = "X-l" ]; then
pod=$1
shift
namespace="-n $1"
shift
fi
exec kubectl $namespace exec -i $pod -- "$@"
- Here's how you run the
krsync
script with entr
:
find . -not -path '*node_modules*' -not -path '*.git*' -not -path '*test*' | entr krsync -av --progress --stats --exclude 'node_modules' --exclude '.git' --exclude 'config/env' . $pod:/opt/bigpanda/public-api