Getting shell access in a container

Let's perform the following steps to create a deployment with multiple containers and get a shell into running containers:

  1. In this recipe, we will deploy PostgreSQL on OpenEBS persistent volumes to demonstrate shell access. Change the directory to the example files directory in src/chapter10/postgres, which is where all the YAML manifest for this recipe are stored. Create a ConfigMap with a database name and credentials similar to the following or review them and use the cm-postgres.yaml file:
$ cd postgres
$ cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: ConfigMap
metadata:
name: postgres-config
labels:
app: postgres
data:
POSTGRES_DB: postgresdb
POSTGRES_USER: testuser
POSTGRES_PASSWORD: testpassword123
EOF
  1. Create the service for postgres:
$ cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Service
metadata:
name: postgres
labels:
app: postgres
spec:
type: NodePort
ports:
- port: 5432
selector:
app: postgres
EOF
  1. Review the postgres.yaml file and apply it to create the PostgreSQL StatefulSet. We can use this to deploy the pods and to auto-create the PV/PVC:
$ kubectl apply -f postgres.yaml
  1. Get the pods with the postgres label:
$ kubectl get pods -l app=postgres
NAME READY STATUS RESTARTS AGE
postgres-0 1/1 Running 0 7m5s
postgres-1 1/1 Running 0 6m58s
  1. Get a shell into the postgres-0 container:
$ kubectl exec -it postgres-0 -- /bin/bash

The preceding command will get you shell access to the running container.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.126.199