Setup Kubernetes Cluster

Posted on August 1, 2022
Tags: devops

1 Running postgres pod in a docker-like manner

In a .yaml file the - containerPort=5432 (your program determines this port)

# --port=5432 aka containerPort determines the local port INSIDE the pod 
# hitting 127.0.0.1:5432 wont work
kubectl run postgrespod --image=postgres --restart=Never --port=5432 --env="POSTGRES_PASSWORD=root" --labels="app=mypostgres,env=prod"

# container port 5432 ==> 127.0.0.1:8098
kubectl port-forward postgres 8098:5432

# container port 5432 ==> postgres on 0.0.0.0:8098
kubectl port-forward postgres 8098:5432 --address='0.0.0.0'

#demo
psql -h 127.0.0.1 -p 8098 -U postgres
kubectl run cockroachdb --image=cockroachdb/cockroach --restart=Never --port=26257 -- start-single-node --insecure --logtostderr