The Side-car Pattern

Before diving into the Operator Framework, this path will give an overview of Kubernetes API fundamentals. Although the Operator SDK simplifies the task of creating an Operator, you need some understanding of the structure and features of the Kubernetes API.

Create a new namespace called `myproject` and set it as the default namespace for your kubectl commands:

kubectl create namespace myproject
kubectl config set-context --current --namespace=myproject

Create a new pod manifest that specifies two containers:

cat > pod-multi-container.yaml <<EOF
apiVersion: v1
kind: Pod
metadata:
  name: my-two-container-pod
  namespace: myproject
  labels:
    environment: dev
spec:
  containers:
    - name: server
      image: nginx:1.13-alpine
      ports:
        - containerPort: 80
          protocol: TCP
    - name: side-car
      image: alpine:latest
      command: ["/usr/bin/tail", "-f", "/dev/null"]
  restartPolicy: Never
EOF

Create the pod by specifying the manifest:

kubectl create -f pod-multi-container.yaml

View the details for the pod and look at the events:

kubectl describe pod my-two-container-pod

Execute a shell session inside the server container by specifying it with the `-c` argument:

kubectl exec -it my-two-container-pod -c server -- /bin/sh

Run some commands inside the server container:

ip address
netstat -ntlp
hostname
ps -ef
exit

Execute a shell session inside the side-car container:

kubectl exec -it my-two-container-pod -c side-car -- /bin/sh

Run the same commands in side-car container. Each container within a pod runs its own cgroup, but shares IPC, Network, and UTC (hostname) namespaces.

ip address
netstat -ntlp
hostname
ps -ef
exit