Skip to content

Helm template for Antifragile patterns

Estimated time to read: 4 minutes

Creating a single Helm chart to demonstrate antifragile patterns in a single application may not be feasible, as some patterns are more relevant to specific use cases or system architectures. However, I can provide you with a sample Helm chart that includes some of these patterns and comments on how to implement other patterns.

Find below a Helm chart demonstrating a simple application with some antifragile patterns. Please note that you must replace your-docker-image with your actual Docker image name.

Chart.yaml:

YAML
apiVersion: v2
name: antifragile-demo
description: A Helm chart demonstrating antifragile patterns
version: 0.1.0

values.yaml:

YAML
replicaCount: 2  # Redundancy

image:
  repository: your-docker-image
  pullPolicy: IfNotPresent

service:
  type: ClusterIP
  port: 80

ingress:
  enabled: false
  annotations: {}
  hosts:
    - host: chart-example.local
      paths:
        - /
  tls: []

resources: {}

autoscaling:
  enabled: false
  minReplicas: 2
  maxReplicas: 4
  targetCPUUtilizationPercentage: 50

istio:
  enabled: true
  retries: 3
  timeout: 5s
  rateLimit:
    enabled: true
    requestsPerSecond: 5
    burst: 10
  loadShedding:
    enabled: true
    httpRequestTimeout: 5s
    maxRetries: 3
    retryOn: "5xx,connect-failure,refused-stream"
  circuitBreaker:
    consecutiveErrors: 5
    interval: 5s
    baseEjectionTime: 30s
    maxEjectionPercent: 10
  connectionPool:
    http:
      http1MaxPendingRequests: 1024
      maxRequestsPerConnection: 10
    tcp:
      maxConnections: 1024
      connectTimeout: 5s

templates/deployment.yaml:

YAML
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "antifragile-demo.fullname" . }}
  labels:
    {{- include "antifragile-demo.labels" . | nindent 4 }}
spec:
  replicas: {{ .Values.replicaCount }}  # Redundancy
  selector:
    matchLabels:
      {{- include "antifragile-demo.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      labels:
        {{- include "antifragile-demo.selectorLabels" . | nindent 8 }}
      annotations:
        sidecar.istio.io/rewriteAppHTTPProbers: "true"
    spec:
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ .Values.image.repository }}:{{ .Chart.AppVersion }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          ports:
            - name: http
              containerPort: 80
              protocol: TCP
          resources:
            {{- toYaml .Values.resources | nindent 12 }}

templates/service.yaml:

YAML
apiVersion: v1
kind: Service
metadata:
  name: {{ include "antifragile-demo.fullname" . }}
  labels:
    {{- include "antifragile-demo.labels" . | nindent 4 }}
spec:
  type: {{ .Values.service.type }}
  ports:
    - port: {{ .Values.service.port }}
      targetPort: http
      protocol: TCP
      name: http
  selector:
    {{- include "antifragile-demo.selectorLabels" . | nindent 4 }}

templates/hpa.yaml:

YAML
{{- if .Values.autoscaling.enabled }}
apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
  name: {{ include "antifragile-demo.fullname" . }}
  labels:
    {{- include "antifragile-demo.labels" . | nindent 4 }}
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: {{ include "antifragile-demo.fullname" . }}
  minReplicas: {{ .Values.autoscaling.minReplicas }}
  maxReplicas: {{ .Values.autoscaling.maxReplicas }}
  targetCPUUtilizationPercentage: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
{{- end }}

templates/istio-virtual-service.yaml:

YAML
{{- if .Values.istio.enabled }}
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: {{ include "antifragile-demo.fullname" . }}
spec:
  hosts:
    - "*"
  gateways:
    - istio-system/istio-autogenerated-k8s-ingress
  http:
    - match:
        - uri:
            prefix: /
      route:
        - destination:
            host: {{ include "antifragile-demo.fullname" . }}.{{ .Release.Namespace }}.svc.cluster.local
          port:
            number: 80
      retries:
        attempts: {{ .Values.istio.loadShedding.maxRetries }}
        perTryTimeout: {{ .Values.istio.loadShedding.httpRequestTimeout }}
        retryOn: {{ .Values.istio.loadShedding.retryOn }}
      timeout: {{ .Values.istio.loadShedding.httpRequestTimeout }}
{{- end }}

templates/istio-destination-rule.yaml:

YAML
{{- if .Values.istio.enabled }}
apiVersion: networking.istio.io/v1beta1
kind: DestinationRule
metadata:
  name: {{ include "antifragile-demo.fullname" . }}
spec:
  host: {{ include "antifragile-demo.fullname" . }}.{{ .Release.Namespace }}.svc.cluster.local
  trafficPolicy:
    connectionPool:
      http:
        http1MaxPendingRequests: {{ .Values.istio.connectionPool.http.http1MaxPendingRequests }}
        maxRequestsPerConnection: {{ .Values.istio.connectionPool.http.maxRequestsPerConnection }}
      tcp:
        maxConnections: {{ .Values.istio.connectionPool.tcp.maxConnections }}
        connectTimeout: {{ .Values.istio.connectionPool.tcp.connectTimeout }}
    outlierDetection:
      consecutiveErrors: {{ .Values.istio.circuitBreaker.consecutiveErrors }}
      interval: {{ .Values.istio.circuitBreaker.interval }}
      baseEjectionTime: {{ .Values.istio.circuitBreaker.baseEjectionTime }}
      maxEjectionPercent: {{ .Values.istio.circuitBreaker.maxEjectionPercent }}
{{- if .Values.istio.rateLimit.enabled }}
    loadBalancer:
      simple: LEAST_CONN
    rateLimit:
      http1MaxPendingRequests: {{ .Values.istio.rateLimit.requestsPerSecond }}
{{- end }}
{{- end }}

These templates demonstrate several antifragile patterns, including Redundancy, Self-healing, Rate limiting, Monitoring and observability (when combined with Prometheus and Grafana), and Adaptive capacity Circuit breakers, Bulkheads, Isolation, and Timeouts: Use Istio to apply these patterns on the network level between microservices. Graceful degradation: Design your application to handle partial failures and continue functioning at reduced capacity. Load shedding: Use rate limiting and adaptive capacity to prevent system overload.

To cover other antifragile patterns, consider the following:

  • Diversity: Deploy multiple versions of your application or use different technology stacks for different components.
  • Modularity: Break your application into smaller, independent components (microservices).
  • Loose coupling: Minimize dependencies between components and design them to communicate through well-defined interfaces.
  • Feedback loops: Continuously monitor the health and performance of your system and use the collected data to adjust and improve.

To deploy the Helm chart:

Bash
helm install antifragile-demo ./path/to/your/helm/chart

Remember that this example template. You need to provide the details required to run in your environment.