I am new to K8S and Terraform. I installed ingress_nginx on K8S Cluster running on Bare-metal.
[root@control02 ~]# kubectl get svc -n ingress-nginx
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
docker-hello-world-svc NodePort 10.xx.xx.121 <none> 8086:30333/TCP 13d
ingress-nginx-controller NodePort 10.xx.xx.124 <none> 80:31545/TCP,443:30198/TCP 13d
ingress-nginx-controller-admission ClusterIP 10.xx.xx.85 <none> 443/TCP 13d
I created Deployment, Service and Ingress and am able to access the docker-hello-world-svc from browser successfully. Ingress.yaml is given below
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: hello-world-ing
annotations:
kubernetes.io/ingress.class: "nginx"
namespace: ingress-nginx
spec:
#ingressClassName : nginx
rules:
- host: foo.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: docker-hello-world-svc
port:
number: 8086
My requirement is to containerize our PHP based applications on K8S Cluster.
-
Creating ingress via Terraform’s
resource "kubernetes_ingress" "web"
andingress.yaml:kubernetes.io/ingress.class
are same (or) are they different? -
How can I create ‘ingress’ on K8S Cluster machine using Terraform ?
For example, when I trigger a job from GitLab, Terraform should create a new
"resource kubernetes_ingress"
on K8S Cluster or Control-Plane machine. Is this possible ?
Kindly clarify on the queries mentioned above and let me know if my understanding is wrong
3
Answers
I was able to create the service on existing K8S Cluster (Bare metal) using the following code
K8S Cluster was setup on
192.168.xxx.xxx
on which I created a serviceexample
. We need to mention the'host'
parameter inside'kubernetes'
blockThe
ingress.class
is needed to let the nginx ingress controller understand thathe need to handle this resource.To create an ingress with terraform you can use the following
for,
this,
should now be,
see,