Skip to content

Instantly share code, notes, and snippets.

@chanwit
Last active August 25, 2022 07:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chanwit/a46118687782585d2e31af3100cac370 to your computer and use it in GitHub Desktop.
Save chanwit/a46118687782585d2e31af3100cac370 to your computer and use it in GitHub Desktop.

Install kustomize

brew install kustomize

Prepare namespace prefix

export NS_PREFIX=chanwit

Create 2 directories

mkdir podinfo
mkdir prod

Create 2 Subnamespaces

Don't forget to prefix the objects with your name first.

cat <<EOF | kubectl apply -f -
---
apiVersion: hnc.x-k8s.io/v1alpha2
kind: SubnamespaceAnchor
metadata:
  namespace: team-denim
  name: ${NS_PREFIX}-dev
---
apiVersion: hnc.x-k8s.io/v1alpha2
kind: SubnamespaceAnchor
metadata:
  namespace: team-denim
  name: ${NS_PREFIX}-prod
EOF

Check Subnamespaces

kubectl get subns

Go into podinfo DIR

cd podinfo
# download deployment.yaml and service.yaml, place them in the podinfo dir

Run Kustomize

kustomize create --autodetect --namespace=${NS_PREFIX}-dev
cat kustomization.yaml

Run Kustomize Build

kustomize build .

Now move to the prod DIR

cd ../prod
kustomize create --resources ../podinfo --namespace ${NS_PREFIX}-prod
# This is the real flags used by Flux when process the FLux's Kustomization objects.
kustomize build --load-restrictor=LoadRestrictionsNone --reorder=legacy .
apiVersion: apps/v1
kind: Deployment
metadata:
name: podinfo
spec:
minReadySeconds: 3
revisionHistoryLimit: 5
progressDeadlineSeconds: 60
strategy:
rollingUpdate:
maxUnavailable: 0
type: RollingUpdate
selector:
matchLabels:
app: podinfo
template:
metadata:
annotations:
prometheus.io/scrape: "true"
prometheus.io/port: "9797"
labels:
app: podinfo
spec:
containers:
- name: podinfod
image: ghcr.io/stefanprodan/podinfo:6.2.0
imagePullPolicy: IfNotPresent
ports:
- name: http
containerPort: 9898
protocol: TCP
- name: http-metrics
containerPort: 9797
protocol: TCP
- name: grpc
containerPort: 9999
protocol: TCP
command:
- ./podinfo
- --port=9898
- --port-metrics=9797
- --grpc-port=9999
- --grpc-service-name=podinfo
- --level=info
- --random-delay=false
- --random-error=false
env:
- name: PODINFO_UI_COLOR
value: "#34577c"
livenessProbe:
exec:
command:
- podcli
- check
- http
- localhost:9898/healthz
initialDelaySeconds: 5
timeoutSeconds: 5
readinessProbe:
exec:
command:
- podcli
- check
- http
- localhost:9898/readyz
initialDelaySeconds: 5
timeoutSeconds: 5
resources:
limits:
cpu: 2000m
memory: 512Mi
requests:
cpu: 100m
memory: 64Mi
apiVersion: v1
kind: Service
metadata:
name: podinfo
spec:
type: ClusterIP
selector:
app: podinfo
ports:
- name: http
port: 9898
protocol: TCP
targetPort: http
- port: 9999
targetPort: grpc
protocol: TCP
name: grpc
---
apiVersion: hnc.x-k8s.io/v1alpha2
kind: SubnamespaceAnchor
metadata:
namespace: team-denim
name: <your-user>-dev
---
apiVersion: hnc.x-k8s.io/v1alpha2
kind: SubnamespaceAnchor
metadata:
namespace: team-denim
name: <your-user>-prod
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment