Kubernetes Pods

Preface

Docker Containers

# Suppose the CI tool already build the `foo` service as a executable binary file and saved it in `./go-server`.

FROM alpine:3.5

RUN apk update && apk add ca-certificates && rm -rf /var/cache/apk/*

COPY ./go-server /usr/bin/server

ENTRYPOINT ["/usr/bin/server"]

Pod Overview

Use of Pods

# ConfigMap for user-msvc
apiVersion: v1
kind: ConfigMap
metadata:
name: user-msvc
namespace: user-msvc
data:
mysql-host: 127.0.0.1:3306

---
# Secret of user-msvc
apiVersion: v1
kind: Secret
metadata:
name: user-msvc
namespace: user-msvc
type: Opaque
data:
datadog-api-key: XKSSAKCKANmOWQ5NDU1NWU2MWE2ZDI=
github-access-token: Yzk4MDZkNzAxNTQwMjkwOA==
# All other configs are omitted.

---
# Pod for user-msvc
apiVersion: v1
kind: Pod
metadata:
name: user-msvc
namespace: user-msvc
labels:
app: user-msvc
spec:
# Storage
volumes:
- name: datadog-data
emptyDir: {}
- name: user-msvc-secret
secret:
defaultMode: 420
secretName: user-msvc-secret

# "Processes"
containers:
- name: user-msvc
image: gcr.io/path/to/user-msvc:1.0.0
ports:
- name: secure-port
containerPort: 443
protocol: TCP
env:
- name: MYSQL_HOST
valueFrom:
configMapKeyRef:
name: user-msvc
key: mysql-host
volumeMounts:
- name: ndatadog-data
mountPath: /var/log/user-msvc
- name: user-msvc-secret
mountPath: /etc/user-msvc/secret
requests:
cpu: 100m
memory: 100Mi
limits:
cpu: 200m
memory: 200Mi

- name: cloudsql-proxy
image: gcr.io/cloudsql-docker/gce-proxy:1.12
ports:
- name: connect-port
containerPort: 3306
protocol: TCP
requests:
...

- name: datadog-agent
image: gcr.io/path/to/monitor:1.0.0
volumeMounts:
- name: datadog-data
mountPath: /var/log/monitor
- name: user-msvc-secret
mountPath: /etc/datadog-agent/secret
requests:
...
---


# External Service for user-msvc
kind: Service
apiVersion: v1
metadata:
name: user-msvc
spec:
ports:
- name: secure-port
port: 443
targetPort: 443
protocol: TCP
selector:
app: user-msvc
type: LoadBalancer
loadBalancerIP: 12.34.56.78 # This is a fake IP

What Is Next

Reference

--

--

A software engineer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store