From 50a80c97cc28eb05c83c7ba91c4cb2c26bccaf2f Mon Sep 17 00:00:00 2001 From: Obasoro Olakunle Date: Wed, 3 Apr 2024 09:05:57 -0500 Subject: [PATCH 1/2] working on gitops --- chapter-02/contrl | 42 ++++++++++++++++++++++++++ chapter-02/declarative-deployment.yaml | 2 +- chapter-02/imperative.sh | 4 +++ 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 chapter-02/contrl create mode 100755 chapter-02/imperative.sh diff --git a/chapter-02/contrl b/chapter-02/contrl new file mode 100644 index 0000000..67fb0c7 --- /dev/null +++ b/chapter-02/contrl @@ -0,0 +1,42 @@ +#!/usr/bin/env bash + +kubectl get --watch --output-watch-events configmap \ +-o=custom-columns=type:type,name:object.metadata.name \ +--no-headers | \ +while read next; do + NAME=$(echo $next | cut -d' ' -f2 | tr '.' '-') # Replace '.' with '-' + EVENT=$(echo $next | cut -d' ' -f1) + + case $EVENT in + ADDED|MODIFIED) + kubectl apply -f - << EOF +apiVersion: apps/v1 +kind: Deployment +metadata: { name: $NAME } +spec: + selector: + matchLabels: { app: $NAME } + template: + metadata: + labels: { app: $NAME } + annotations: { kubectl.kubernetes.io/restartedAt: $(date) } + spec: + containers: + - image: nginx:1.7.9 + name: $NAME + ports: + - containerPort: 80 + volumeMounts: + - { name: data, mountPath: /usr/share/nginx/html } + volumes: + - name: data + configMap: + name: $NAME +EOF + ;; + DELETED) + kubectl delete deploy $NAME + ;; + esac +done + diff --git a/chapter-02/declarative-deployment.yaml b/chapter-02/declarative-deployment.yaml index b916ff1..7b1f416 100644 --- a/chapter-02/declarative-deployment.yaml +++ b/chapter-02/declarative-deployment.yaml @@ -4,7 +4,7 @@ metadata: name: nginx-declarative annotations: environment: prod - organization: sales + organization: marketing spec: replicas: 3 selector: diff --git a/chapter-02/imperative.sh b/chapter-02/imperative.sh new file mode 100755 index 0000000..7b86102 --- /dev/null +++ b/chapter-02/imperative.sh @@ -0,0 +1,4 @@ +kubectl create deployment nginx-imperative --image=nginx:latest +kubectl scale deployment/nginx-imperative --replicas 3 +kubectl annotate deployment/nginx-imperative environment=prod +kubectl annotate deployment/nginx-imperative organization=sales From ce6c39f3f96291c27cec0a3e34f1dc509f370534 Mon Sep 17 00:00:00 2001 From: Obasoro Olakunle Date: Wed, 3 Apr 2024 09:25:17 -0500 Subject: [PATCH 2/2] delete controller.sh --- chapter-02/contrl | 42 ---------------------------------------- chapter-02/controller.sh | 11 +++++------ 2 files changed, 5 insertions(+), 48 deletions(-) delete mode 100644 chapter-02/contrl diff --git a/chapter-02/contrl b/chapter-02/contrl deleted file mode 100644 index 67fb0c7..0000000 --- a/chapter-02/contrl +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/env bash - -kubectl get --watch --output-watch-events configmap \ --o=custom-columns=type:type,name:object.metadata.name \ ---no-headers | \ -while read next; do - NAME=$(echo $next | cut -d' ' -f2 | tr '.' '-') # Replace '.' with '-' - EVENT=$(echo $next | cut -d' ' -f1) - - case $EVENT in - ADDED|MODIFIED) - kubectl apply -f - << EOF -apiVersion: apps/v1 -kind: Deployment -metadata: { name: $NAME } -spec: - selector: - matchLabels: { app: $NAME } - template: - metadata: - labels: { app: $NAME } - annotations: { kubectl.kubernetes.io/restartedAt: $(date) } - spec: - containers: - - image: nginx:1.7.9 - name: $NAME - ports: - - containerPort: 80 - volumeMounts: - - { name: data, mountPath: /usr/share/nginx/html } - volumes: - - name: data - configMap: - name: $NAME -EOF - ;; - DELETED) - kubectl delete deploy $NAME - ;; - esac -done - diff --git a/chapter-02/controller.sh b/chapter-02/controller.sh index a5fb803..67fb0c7 100755 --- a/chapter-02/controller.sh +++ b/chapter-02/controller.sh @@ -1,16 +1,14 @@ - #!/usr/bin/env bash kubectl get --watch --output-watch-events configmap \ -o=custom-columns=type:type,name:object.metadata.name \ --no-headers | \ -while read next; do #B - - NAME=$(echo $next | cut -d' ' -f2) #C +while read next; do + NAME=$(echo $next | cut -d' ' -f2 | tr '.' '-') # Replace '.' with '-' EVENT=$(echo $next | cut -d' ' -f1) case $EVENT in - ADDED|MODIFIED) #D + ADDED|MODIFIED) kubectl apply -f - << EOF apiVersion: apps/v1 kind: Deployment @@ -36,8 +34,9 @@ spec: name: $NAME EOF ;; - DELETED) #E + DELETED) kubectl delete deploy $NAME ;; esac done +