Skip to content

Instantly share code, notes, and snippets.

type Repository struct {
apiRateLimitter *rate.Limiter
}
func NewRepository() *Repository {
return &Repository{
apiRateLimitter: rate.NewLimiter(rate.Every(time.Second/time.Duration(config.GetInt("API_RPS"))), 1),
}
}
# Deployment
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: your-deployment
namespace: your-namespace
labels:
app: your-application
spec:
replicas: ${REPLICAS_COUNT}
metadata:
labels:
app: app-name
process: app-process
product: app-product
REPLICAS_COUNT=$(kubectl -s $K8S_CLUSTER --token=$K8S_TOKEN -n $NAMESPACE get pods -l app=$YOUR_APP | grep -i running | wc -l | grep -oE "[0-9]+")
if [ $REPLICAS_COUNT -eq 0 ]; then
REPLICAS_COUNT=2
fi
REPLICAS_COUNT=$REPLICAS_COUNT envsubst < deploy/your-deployment.yaml.template > your-deployment.yaml
selector:
matchLabels:
app: app-name
process: app-process
product: app-product
minAvailable: 50%
scaleTargetRef:
apiVersion: apps/v1beta1
kind: Deployment
name: deploymentName
minReplicas: 6
maxReplicas: 60
targetCPUUtilizationPercentage: 50
resources:
requests:
memory: 1Gi
cpu: 1
limits:
memory: 1Gi
cpu: 1
livenessProbe:
failureThreshold: 3
httpGet:
path: /healthcheck/status
port: 3000
initialDelaySeconds: 10
periodSeconds: 60
readinessProbe:
failureThreshold: 2
httpGet:
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: labelKey
operator: In
values:
- labelValue
topologyKey: kubernetes.io/hostname
replicas: 2
minReadySeconds: 60
strategy:
rollingUpdate:
maxSurge: 3
maxUnavailable: 0
type: RollingUpdate