ECD Patch is meant to provide a flexible option for users to define and provision Kubernetes objects that suits their system architecture or to tailor the ECD to their preferred flavour.
...
Code Block |
---|
services:
- spec:
type: ClusterIP
ports:
- port: 9092
protocol: TCP
targetPort: 9092
...
...
patchType: "application/strategic-merge-patch+json"
patch: |
spec:
ports:
- name: "port-1"
port: 9093
protocol: TCP
targetPort: 9093
- name: "port-2"
port: 9094
protocol: UDP
targetPort: 9094
... |
Samples
To help users to understand better, below are some samples that can get users started using ECD patch. Do note that “Before” is based on the ECD - which is the definition file for the desired state. while “After” is based on the conversion and logic processing done by Operator - which is the actual objects provisioning yaml to be applied to the cluster. As you might notice, there are a lot more objects that will be provisioned and handled by Operator itself.
Changing Rollout Strategy
Basically, an ECD will resulting in creating different K8S objects, 1 of them is Deployment object. The rollout strategy is default to RollingUpdate, through ECD patch we can change it to other strategy such as Recreate. The change can be seen on the spec.strategy.typeon After ECD Patch.
Before ECD Patch | After ECD Patch |
---|
k apply -f file.yaml
Code Block |
---|
apiVersion: mz.digitalroute.com/v1alpha1
kind: ECDeployment
metadata:
name: ecd-test-rolling-strategy
spec:
enabled: true
patchType: "application/strategic-merge-patch+json"
patch: |
spec:
strategy:
type: Recreate
image: dtr.digitalroute.com/dr/mz10:10.1.0.0-dev-20200813052033.a224284-ec
workflows:
- template: Default.http2
instances:
- name: server-1
parameters: |
{
"port": 8989
} |
| k get deploy ecd-test-rolling-strategy -o yaml
Code Block |
---|
apiVersion: apps/v1
kind: Deployment
metadata:
...
...
spec:
progressDeadlineSeconds: 600
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
app: ecd-test-rolling-strategy
strategy:
type: Recreate
template:
...
... |
|
Setting Toleration
In example below, assuming a 3 nodes implementation K8S cluster, 2 nodes are tainted color=blue and 1 node is tainted color=red, the test is to add toleration to ECD so that it will get deployed into node tainted with color=red.
...
Before ECD Patch | After ECD Patch |
---|
k apply -f file.yaml
Code Block |
---|
apiVersion: mz.digitalroute.com/v1alpha1
kind: ECDeployment
metadata:
name: ecd-test-tolerations
spec:
enabled: true
patchType: "application/strategic-merge-patch+json"
patch: |
spec: # Spec for Deployment
template: # Template for Pods
spec: # Spec for Pods
tolerations: # Toleration added to each Pod
- key: "color"
value: "red"
operator: "Equal"
effect: "NoSchedule"
image: dtr.digitalroute.com/dr/mz10:10.1.0.0-dev-20200813052033.a224284-ec
workflows:
- template: Default.http2
instances:
- name: server-1
parameters: |
{
"port": 8989
} |
| k get pods ecd-test-tolerations-5d646c45cd-g9x8n -o wide
Code Block |
---|
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
ecd-test-tolerations-5d646c45cd-g9x8n 1/1 Running 0 80s 10.244.2.10 kl-kube-node03.digitalroute.com <none> <none> |
k describe pods ecd-test-tolerations-5d646c45cd-g9x8n| grep -i toleration
Code Block |
---|
Name: ecd-test-tolerations-5d646c45cd-g9x8n
Labels: ECDeployment=ecd-test-tolerations
app=ecd-test-tolerations
Controlled By: ReplicaSet/ecd-test-tolerations-5d646c45cd
ecd-test-tolerations:
Tolerations: color=red:NoSchedule
Normal Scheduled 5m21s default-scheduler Successfully assigned castle-black/ecd-test-tolerations-5d646c45cd-g9x8n to kl-kube-node03.digitalroute.com
Normal Created 5m21s kubelet, kl-kube-node03.digitalroute.com Created container ecd-test-tolerations
Normal Started 5m20s kubelet, kl-kube-node03.digitalroute.com Started container ecd-test-tolerations |
|
Setting Environment Variable
There might be a case where you would like to add in an environment variable. In the example below, we will add one calls ENV where the value will be “dev”.
Before ECD Patch | After ECD Patch |
---|
k apply -f file.yaml
Code Block |
---|
apiVersion: mz.digitalroute.com/v1alpha1
kind: ECDeployment
metadata:
name: ecd-test-2
spec:
enabled: true
patchType: "application/strategic-merge-patch+json"
patch: |
spec:
template:
spec:
containers:
- name: ecd-test-2
env:
- name: ENV
value: dev
image: dtr.digitalroute.com/dr/mz10:10.1.0.0-dev-20200813052033.a224284-ec
workflows:
- template: Default.http2
instances:
- name: server-1
parameters: |
{
"port": 8989
} |
| kex ecd-test-2-7487469546-s77xx bash -- printenv | grep ENV
k describe pods ecd-test-2-7487469546-s77xx
Code Block |
---|
Name: ecd-test-2-7487469546-s77xx
Namespace: castle-black
Priority: 0
Node: kl-kube-node03.digitalroute.com/10.60.10.143
Start Time: Tue, 25 Aug 2020 17:05:04 +0800
Labels: ECDeployment=ecd-test-2
app=ecd-test-2
pod-template-hash=7487469546
Annotations: Status: Running
IP: 10.244.2.14
IPs:
IP: 10.244.2.14
Controlled By: ReplicaSet/ecd-test-2-7487469546
Containers:
ecd-test-2:
Container ID: docker://a07de37d1cfff80b7ce240d7a6d3821cea393a49b58f8a9f43f97a229efd236f
Image: dtr.digitalroute.com/dr/mz10:10.1.0.0-dev-20200813052033.a224284-ec
Image ID: docker-pullable://dtr.digitalroute.com/dr/mz10@sha256:6e5efb5bb8e526679d2e0878f5cf69011d0f8724be1dc90f26e631f33afe8227
Port: <none>
Host Port: <none>
Command:
/opt/mz/entrypoint/docker-entrypoint.sh
Args:
-e accepts.any.scheduling.criteria=false
State: Running
Started: Tue, 25 Aug 2020 17:05:05 +0800
Ready: True
Restart Count: 0
Liveness: http-get http://:9090/health/live delay=90s timeout=10s period=15s #success=1 #failure=3
Readiness: http-get http://:9090/health/ready delay=0s timeout=1s period=5s #success=1 #failure=60
Environment:
ENV: dev
TZ: UTC
|
|
Mounting a storage
In this scenario, we might want to attach a storage (be it temporary or permanent) in the ECD Pods, perhaps for Batch workflow processing files. In below example, we are attaching a temporary storage (live as long as Pod’s lifespan) and mounting it to the pod.
Before ECD Patch | After ECD Patch |
---|
k apply -f file.yaml
Code Block |
---|
apiVersion: mz.digitalroute.com/v1alpha1
kind: ECDeployment
metadata:
name: ecd-test-2
spec:
enabled: true
patchType: "application/strategic-merge-patch+json"
patch: |
spec:
template:
spec:
containers:
- name: ecd-test-2
volumeMounts:
- mountPath: /cdr_volume
name: cdr-volume
volumes:
- name: cdr-volume
emptyDir: {}
image: dtr.digitalroute.com/dr/mz10:10.2.0-xe-2080-bugfix-latest-ec
workflows:
- template: Default.http2
instances:
- name: server-1
parameters: |
{
"port": 8989
} |
| kg pods ecd-test-2-678ccb76d6-s49ql -o yaml
Code Block |
---|
apiVersion: v1
kind: Pod
metadata:
...
...
name: ecd-test-2-678ccb76d6-s49ql
...
...
spec:
containers:
- name: ecd-test-2
...
...
volumeMounts:
- mountPath: /cdr_volume
name: cdr-volume
- mountPath: /etc/config/common
name: common-config
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
name: default-token-4dc54
readOnly: true
...
...
volumes:
- emptyDir: {}
name: cdr-volume
- configMap:
defaultMode: 420
name: common-config
name: common-config
- name: default-token-4dc54
secret:
defaultMode: 420
secretName: default-token-4dc54
status:
...
...
|
|
Removing an Object
We may also use ECD Patch to remove a provisioned K8S object. From mounting a storage example, now we can use the directive marker ( $patch: delete ) to remove the volume and volumeMount.
...