Reputation: 1339
We have a kubernetes Ingress
object defined. All the ingress rules are not available when defining object for the first time, hence we would like to append rules to it on the fly when configuring respective services to use with it.
Example:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
alb.ingress.kubernetes.io/certificate-arn: ${acm_arn}
alb.ingress.kubernetes.io/scheme: internet-facing
alb.ingress.kubernetes.io/target-type: instance
kubernetes.io/ingress.class: alb
name: ${ingress_name}
namespace: ${namespace}
spec:
rules:
- host: api.${region}.infra.${hosted_zone}
http:
paths:
- backend:
service:
name: istio-ingressgateway
port:
number: 80
path: /*
pathType: Prefix
- http:
paths:
- backend:
service:
name: nginx-ingress-controller
port:
number: 80
path: /*
pathType: Prefix
The above object is created in the beginning. Now, we would like to append a third rule to it at later point in time.
apiVersion: networking.k8s.io/v1
kind: Ingress
name: ${ingress_name}
namespace: ${namespace}
spec:
rules:
- host: api.${region}.${some_dynamic_variable}.${hosted_zone}
http:
paths:
- backend:
service:
name: istio-ingressgateway
port:
number: 80
path: /*
pathType: Prefix
I could have used kubectl patch
but because the merge strategy is not specified in the api docs, I understand it follows the merge strategy replace
which is not what I intend to do.
What is the best available option to get this issue resolved?
Upvotes: 0
Views: 1738
Reputation: 21
There is a kubectl
plugin called ingress-rule
. It allows you to configure an Ingress on the command line.
The plugin is available via krew
. If you have krew
installed simply install the plugin with:
kubectl krew install ingress-rule
Add a new rule to a existing Ingress:
kubectl ingress-rule -n $NAMESPACE set $INGRESSNAME --service $SERVICENAME --port 80 --host $HOST
Delete the previously added rule:
kubectl ingress-rule -n $NAMESPACE delete $INGRESSNAME --service $SERVICENAME
Upvotes: 2