athens-proxy
Athens proxy server for golang
About this chart
Athens - A Go module datastore and proxy
[!NOTE] This is not the official helm chart of Athens Go Proxy. If you are looking for the official helm chart, checkout the GitHub project gomods/athens-charts.
This helm chart enables the deployment of Athens Go Proxy, a module datastore and proxy for Golang.
The helm chart supports the individual configuration of additional containers/initContainers, mounting of volumes, defining additional environment variables and much more.
Chapter configuration and installation describes the basics how to configure helm and use it to deploy the exporter. It also contains further configuration examples.
Furthermore, this helm chart contains unit tests to detect regressions and stabilize the deployment. Additionally, this helm chart is tested for deployment scenarios with ArgoCD.
Helm: configuration and installation
- A helm chart repository must be configured, to pull the helm charts from.
- All available parameters are documented in detail below. The parameters can be defined via the helm
--setflag or directly as part of avalues.yamlfile. The following example defines the repository and use the--setflag for a basic deployment.
helm repo add volker.raschek https://charts.cryptic.systems/volker.raschek
helm repo update
helm install athens-proxy volker.raschek/athens-proxy
Instead of passing all parameters via the set flag, it is also possible to define them as part of the values.yaml.
The following command downloads the values.yaml for a specific version of this chart. Please keep in mind, that the
version of the chart must be in sync with the values.yaml. Newer minor versions can have new features. New major
versions can break something!
CHART_VERSION=2.1.0
helm show values volker.raschek/athens-proxy --version "${CHART_VERSION}" > values.yaml
A complete list of available helm chart versions can be displayed via the following command:
helm search repo athens-proxy --versions
The helm chart also contains a persistent volume claim definition. It persistent volume claim is not enabled by default.
Use the --set argument to persist your data.
CHART_VERSION=2.1.0
helm install --version "${CHART_VERSION}" athens-proxy volker.raschek/athens-proxy \
persistence.enabled=true
Examples
The following examples serve as individual configurations and as inspiration for how deployment problems can be solved.
Avoid CPU throttling by defining a CPU limit
If the application is deployed with a CPU resource limit, Prometheus may throw a CPU throttling warning for the application. This has more or less to do with the fact that the application finds the number of CPUs of the host, but cannot use the available CPU time to perform computing operations.
The application must be informed that despite several CPUs only a part (limit) of the available computing time is
available. As this is a Golang application, this can be implemented using GOMAXPROCS. The following example is one way
of defining GOMAXPROCS automatically based on the defined CPU limit like 1000m. Please keep in mind, that the CFS
rate of 100ms - default on each kubernetes node, is also very important to avoid CPU throttling.
Further information about this topic can be found in one of Kanishk's blog posts.
[!NOTE] The environment variable
GOMAXPROCSis set automatically, when a CPU limit is defined. An explicit configuration is not anymore required.Please take care the a CPU limit <
1000mcan also lead to CPU throttling. Please read the linked documentation carefully.
CHART_VERSION=2.1.0
helm install --version "${CHART_VERSION}" athens-proxy volker.raschek/athens-proxy \
--set 'deployment.athensProxy.env.name=GOMAXPROCS' \
--set 'deployment.athensProxy.env.valueFrom.resourceFieldRef.resource=limits.cpu' \
--set 'deployment.athensProxy.resources.limits.cpu=1000m'
TLS encryption
The example shows how to deploy the application with TLS encryption. For example when no HTTP ingress is used for
TLS determination and instead the application it self should determinate the TLS handshake. To generate the TLS
certificate can be used the cert-manager. The chart supports the creation of such a TLS
certificate via cert-manager.io/v1 Certificate resource. Alternatively can be mounted a TLS certificate from a secret.
The secret must be from type kubernetes.io/tls.
If athens-proxy is deployed behind a reverse proxy, for example an ingress nginx controller or Gateway API, please instruct the reverse proxy to establish a TLS encrypted connection to avoid connection problems. The documentation describes configuring Ingress NGINX as well as NGINX Gateway Fabric.
[!WARNING] The following example expects that the cert-manager is deployed and the
Issuernamedathens-proxy-cais present in the same namespace of the helm deployment.
CHART_VERSION=2.1.0
helm install --version "${CHART_VERSION}" athens-proxy volker.raschek/athens-proxy \
--set 'config.certificate.enabled=true' \
--set 'config.certificate.new.issuerRef.kind=Issuer' \
--set 'config.certificate.new.issuerRef.name=athens-proxy-ca'
The environment variables ATHENS_TLSCERT_FILE and ATHENS_TLSKEY_FILE are automatically added and the TLS certificate
and private key are mounted to a pre-defined destination inside the container file system.
Ingress NGINX
The following changes must be applied to enable TLS encryption and authentication on-top between the ingress and backend service.
[!IMPORTANT] The HTTP Version between the ingress nginx and backend must be set to
1.1, as well as the TLS protocol must be set toTLSv1.2. Otherwise can't the nginx establish a TLS connection.
The secret athens-proxy/ingress-nginx-controller-tls contains TLS certificates for the nginx ingress controller. The
TLS certificate must be created manually, for example via cert-manager. It is used by the
nginx for TLS authentication.
ingress:
enabled: true
className: "nginx"
annotations:
nginx.ingress.kubernetes.io/backend-protocol: HTTPS
nginx.ingress.kubernetes.io/proxy-http-version: "1.1"
nginx.ingress.kubernetes.io/proxy-ssl-secret: athens-proxy/ingress-nginx-controller-tls
nginx.ingress.kubernetes.io/proxy-ssl-protocols: TLSv1.2
nginx.ingress.kubernetes.io/proxy-ssl-name: athens-proxy
nginx.ingress.kubernetes.io/proxy-ssl-verify: "on"
GatewayAPI: NGINX Fabric
The following changes must be applied to enable TLS encryption and authentication on-top between the gateway and backend service.
[!IMPORTANT] The HTTP Version between the nginx gateway fabric and backend must be set to
1.1, as well as the TLS protocol must be set toTLSv1.2. Otherwise can't the nginx establish a TLS connection.
The gatewayAPI.core.backendTLSPolicy.validation.caCertificateRefs must contain at least one secret containing the
root or intermediate certificate of the issued TLS certificate used by athens-proxy to be able to validate the TLS
certificate.
gatewayAPI:
enabled: true
core:
backendTLSPolicy:
enabled: true
validation:
caCertificateRefs:
- group: ""
kind: Secret
name: "athens-proxy-ca"
hostname: "athens-proxy"
httpRoute:
enabled: true
hostnames:
- athens-proxy.example.local
parentRefs:
- name: nginx
kind: Gateway
group: gateway.networking.k8s.io
namespace: my-gateway-namespace
sectionName: athens-proxy-https
The Gateway resource is not part of the helm chart, but for illustrating the configuration example, here a GatewayAPI
resource with configured backend TLS certificate. The TLS certificates gateway-frontend-tls and gateway-backend-tls
must also be created manually, for example via cert-manager.
---
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: nginx
namespace: my-gateway-namespace
spec:
gatewayClassName: nginx
listeners:
- allowedRoutes:
kinds:
- group: gateway.networking.k8s.io
kind: HTTPRoute
namespaces:
from: All
hostname: athens-proxy.example.local
name: https
port: 443
protocol: HTTPS
tls:
certificateRefs:
- group: ''
kind: Secret
name: gateway-frontend-tls
namespace: my-gateway-namespace
mode: Terminate
tls:
backend:
clientCertificateRef:
group: ''
kind: Secret
name: gateway-backend-tls
namespace: my-gateway-namespace
TLS certificate rotation
If the application uses TLS certificates that are mounted as a secret in the container file system like the example above, the application will not automatically apply them when the TLS certificates are rotated. Such a rotation can be for example triggered, when the cert-manager issues new TLS certificates before expiring.
Until the exporter does not support rotating TLS certificate a workaround can be applied. For example stakater's reloader controller can be used to trigger a rolling update. The following annotation must be added to instruct the reloader controller to trigger a rolling update, when the mounted secret has been changed.
[!IMPORTANT] The Helm chart already adds annotations to trigger a rolling release. Helm describes this approach under Automatically Roll Deployments. For this reason, only external configMaps or secrets need to be monitored by reloader.
deployment:
annotations:
secret.reloader.stakater.com/reload: "athens-proxy-tls"
If the application is rolled out using ArgoCD, a rolling update from stakater's reloader can lead to a drift. ArgoCD will attempt to restore the original state with a rolling update. To avoid this, instead of a rolling update triggered by the reloader, a restart of the pod can be initiated. Further information are available in the official README of stakater's reloader.
deployment:
annotations:
+ reloader.stakater.com/rollout-strategy: "restart"
secret.reloader.stakater.com/reload: "athens-proxy-tls"
Network policies
Network policies can only take effect, when the used CNI plugin support network policies. The chart supports no custom
network policy implementation of CNI plugins. It's support only the official API resource of networking.k8s.io/v1.
The example below is an excerpt of the values.yaml file. The network policy contains ingress rules to allow incoming
traffic from an ingress controller. Additionally two egress rules are defined. The first one to allow the application
outgoing access to the internal running DNS server core-dns. The second rule to be able to access the upstream Go
proxy https://proxy.golang.org via HTTPS.
[!IMPORTANT] Please keep in mind, that the namespace and pod selector labels can be different from environment to environment. For this reason, there is are not default network policy rules defined.
networkPolicies:
enabled: true
annotations: {}
labels: {}
policyTypes:
- Egress
- Ingress
egress:
- to:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: kube-system
podSelector:
matchLabels:
k8s-app: kube-dns
ports:
- port: 53
protocol: TCP
- port: 53
protocol: UDP
- ports:
- port: 22
protocol: TCP
- ports:
- port: 443
protocol: TCP
ingress:
- from:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: ingress-nginx
podSelector:
matchLabels:
app.kubernetes.io/name: ingress-nginx
# NGINX GatewayAPI Fabric
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: gateway-nginx
podSelector:
matchLabels:
app.kubernetes.io/name: gateway-nginx
ports:
- port: http
protocol: TCP
ArgoCD
Example Application
An application resource for the Helm chart is defined below. It serves as an example for your own deployment.
apiVersion: argoproj.io/v1alpha1
kind: Application
spec:
destination:
server: https://kubernetes.default.svc
namespace: athens-proxy
ignoreDifferences:
- group: apps
kind: Deployment
jqPathExpressions:
# When HPA is enabled, ensure that a modification of the replicas does not lead to a
# drift.
- '.spec.replicas'
# Ensure that changes of the annotations or environment variables added or modified by
# stakater's reloader does not lead to a drift.
- '.spec.template.metadata.annotations | with_entries(select(.key | startswith("reloader")))'
- '.spec.template.spec.containers[].env[] | select(.name | startswith("STAKATER_"))'
sources:
- repoURL: https://charts.cryptic.systems/volker.raschek
chart: athens-proxy
targetRevision: '0.*'
helm:
valueFiles:
- $values/values.yaml
releaseName: athens-proxy
syncPolicy:
Deploy athens-proxy with OpenTenant
Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has athens-proxy on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.
- Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
- Place the chartathens-proxy is pinned at v2.1.0 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
- ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below opentenant validate opentenant.yaml terraform init && terraform apply