My goal is to have a Kubernetes Service with dynamic annotation value, is it possible to bind ConfigMap object within Kubernetes Service annotation. Tried googling the question unfortunately without success. My experience to use ConfigMap only in conjunction with Deployment. My guess it's not possible but wanted to have a confirmation. Probably someone knows a way to have it. I always is able to create my Kubernetes Service using direct kubectl command without providing yaml file and set the annotation value from system env values for example, I'm curious if there more elegant way to do this.
Thanks
Use helm.
This requires setting up a helm "chart" for your deploy which includes a set of yaml templates.
helm create my-app
An example service template with a variable annotation ./my-app/templates/service.yaml
apiVersion: v1
kind: Service
metadata:
labels:
app: my-app-service
name: my-app-service
annotations:
service.beta.kubernetes.io/aws-load-balancer-ssl-cert: {{ .Values.service.certarn }}
spec:
ports:
- name: https
port: 443
protocol: TCP
targetPort: 8091
selector:
app: my-app-instance
type: LoadBalancer
Then the "value" can be set at deploy time:
helm install ./my-app -v certarn=12345:12345:123454513433
Normally you end up with lots of values with a more complex structure so you end up with dev/test/prod values file:
helm install ./my-app -f values.dev.yaml