From ea3135b406f66c7d436d32ddd42a6c36d147c167 Mon Sep 17 00:00:00 2001 From: Marco <marco.lorini@garr.it> Date: Tue, 3 Nov 2020 19:19:06 +0100 Subject: [PATCH] 2020-11-03 ML: update README file with the LibreSpeed application --- README.md | 168 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 98 insertions(+), 70 deletions(-) diff --git a/README.md b/README.md index a0196c7..d148eb6 100644 --- a/README.md +++ b/README.md @@ -179,54 +179,30 @@ As example we used **LibreSpeed** application, for more details about this appli **N.B.**: all commands must be run on Host Cluster. -### Create namespace +### Create ExternalDNS namespace -The first step is create a namespace in the host cluster: +The first step is create a namespace for ExternalDNS in the host cluster: command line: ```bash -$ kubectl create namespace <namespace-name> +$ kubectl create namespace external-dns ``` -or create it by yaml file (resource/namespace.yaml): +or create it by yaml file (externalDNS/namespace.yaml): ```yaml # namespace.yaml file apiVersion: v1 kind: Namespace metadata: - name: fed-namespace -``` - -```bash -$ kubectl create -f resource/namespace.yaml -``` - -### Federate namespace - -Once the namespace is created in the Host Cluster, it can be federate on the Member Cluster: - -```yaml -# federated_namespace.yaml -apiVersion: types.kubefed.io/v1beta1 -kind: FederatedNamespace -metadata: - name: fed-namespace - namespace: fed-namespace -spec: - placement: - clusters: - - name: member-cluster-1 - - name: member-cluster-2 + name: external-dns ``` ```bash -$ kubectl --context=<host-cluster-context> create -f resource/federated_namespace.yaml +$ kubectl create -f externalDNS/namespace.yaml ``` -**N.B.**: the option `--context` is not necessary but make sure that the right context is selected. - ### Create RBAC for ExternalDNS Now it is possible to deploy ExternalDNS in the federated namespace. Create the RBAC for the ExternalDNS: @@ -237,13 +213,13 @@ apiVersion: v1 kind: ServiceAccount metadata: name: external-dns - namespace: fed-namespace + namespace: external-dns --- apiVersion: rbac.authorization.k8s.io/v1beta1 kind: ClusterRole metadata: name: external-dns - namespace: fed-namespace + namespace: external-dns rules: - apiGroups: [""] resources: ["services","endpoints","pods"] @@ -262,7 +238,7 @@ apiVersion: rbac.authorization.k8s.io/v1beta1 kind: ClusterRoleBinding metadata: name: external-dns-viewer - namespace: fed-namespace + namespace: external-dns roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole @@ -270,11 +246,11 @@ roleRef: subjects: - kind: ServiceAccount name: external-dns - namespace: fed-namespace + namespace: external-dns ``` ```bash -$ kubectl --context=<host-cluster-context> create -f resource/rbac_externaldns.yaml +$ kubectl --context=<host-cluster-context> create -f externalDNS/rbac_externaldns.yaml ``` ### Deploy ExternalDNS for PowerDNS @@ -287,7 +263,7 @@ apiVersion: apps/v1 kind: Deployment metadata: name: external-dns - namespace: fed-namespace + namespace: external-dns spec: strategy: type: Recreate @@ -314,12 +290,11 @@ spec: - --registry=txt - --txt-prefix=cname - --domain-filter=<domain> # will make ExternalDNS see only the zones matching provided domain; omit to process all available zones in PowerDNS - - --policy=upsert-only # would prevent ExternalDNS from deleting any records, omit to enable full synchronization - + # - --policy=upsert-only # would prevent ExternalDNS from deleting any records, omit to enable full synchronization ``` ```bash -$ kubectl --context=<host-cluster-context> create -f resource/externaldns.yaml +$ kubectl --context=<host-cluster-context> create -f externalDNS/externaldns.yaml ``` The previous configuration is specific to integrate ExternalDNS with the Multi-Cluster Ingress DNS , in this way it will be possible to obtain the ingress information through the "DNSEndpoint" object. The DNSEndpoint object will be created when the Multi-Cluster Ingress DNS is configured (see below). @@ -339,35 +314,91 @@ The main configuration are: For more details see: https://github.com/kubernetes-sigs/external-dns/blob/master/docs/tutorials/pdns.md. +### Create application namespace + +Create a namespace in the host cluster: + +command line: + +```bash +$ kubectl create namespace fed-librespeed +``` + +or create it by yaml file (resource/namespace.yaml): + +```yaml +# namespace.yaml file +apiVersion: v1 +kind: Namespace +metadata: + name: fed-librespeed +``` + +```bash +$ kubectl create -f resource/namespace.yaml +``` + +### Federate application namespace + +Once the namespace is created in the Host Cluster, it can be federate on the Member Cluster: + +```yaml +# federated_namespace.yaml +apiVersion: types.kubefed.io/v1beta1 +kind: FederatedNamespace +metadata: + name: fed-librespeed + namespace: fed-librespeed +spec: + placement: + clusters: + - name: member-cluster-1 + - name: member-cluster-2 +``` + +```bash +$ kubectl --context=<host-cluster-context> create -f resource/federated_namespace.yaml +``` + +**N.B.**: the option `--context` is not necessary but make sure that the right context is selected. + ### Federate deployment -Now create the federated deployment (for this example we used a simple "Hello World" image): +Now create the federated deployment for LibreSpeed application: ```yaml # federated_deployment.yaml apiVersion: types.kubefed.io/v1beta1 kind: FederatedDeployment metadata: - name: fed-helloworld - namespace: fed-namespace + name: fed-librespeed + namespace: fed-librespeed spec: template: metadata: - name: helloworld + name: fed-librespeed + namespace: fed-librespeed spec: replicas: 2 selector: matchLabels: - app: helloworld + app: librespeed template: metadata: labels: - app: helloworld + app: librespeed spec: containers: - - image: docker.io/csdgarr/hello-world:v1 - name: helloworld + - image: adolfintel/speedtest:latest imagePullPolicy: IfNotPresent + name: librespeed + ports: + - name: http + containerPort: 80 + protocol: TCP + env: + - name: TITLE + value: "GARR <3 LibreSpeed" placement: clusters: - name: member-cluster-1 @@ -377,7 +408,6 @@ spec: clusterOverrides: - path: "/spec/replicas" value: 3 - ``` ```bash @@ -388,35 +418,34 @@ In this way the deployment resource will create inside the member clusters and i ### Federate service -Create the service for the "fed-helloworld" deployment: +Create the service for the "fed-librespeed" deployment: ```yaml # federated_service.yaml apiVersion: types.kubefed.io/v1beta1 kind: FederatedService metadata: - name: fed-helloworld-service - namespace: fed-namespace + name: fed-librespeed-service + namespace: fed-librespeed spec: template: metadata: - name: fed-helloworld-service + name: fed-librespeed-service labels: - app: helloworld + app: librespeed spec: selector: - app: helloworld + app: librespeed type: ClusterIP ports: - name: http - port: 8080 - targetPort: 8080 + port: 80 + targetPort: 80 protocol: TCP placement: clusters: - name: member-cluster-1 - name: member-cluster-2 - ``` ```bash @@ -427,35 +456,34 @@ This is a ClusterIP service, in this way the your application is not exposed and ### Federate ingress -Create the ingress resource to expose the fed-helloworld-service: +Create the ingress resource to expose the fed-librespeed-service: ```yaml # federated_ingress.yaml apiVersion: types.kubefed.io/v1beta1 kind: FederatedIngress metadata: - name: fed-helloworld-ingress - namespace: fed-namespace + name: fed-librespeed-ingress + namespace: fed-librespeed spec: template: metadata: - name: helloworld-ingress + name: fed-librespeed-ingress labels: - app: helloworld + app: librespeed spec: rules: - - host: helloworld.<domain> + - host: librespeed.<domain> http: paths: - path: / backend: - serviceName: fed-helloworld-service - servicePort: 8080 + serviceName: fed-librespeed-service + servicePort: 80 placement: clusters: - name: member-cluster-1 - name: member-cluster-2 - ``` ```bash @@ -485,16 +513,16 @@ The IngressDNSRecord resource can be created in the follow way: apiVersion: multiclusterdns.kubefed.io/v1alpha1 kind: IngressDNSRecord metadata: - name: fed-helloworld-ingress - namespace: fed-namespace + name: fed-librespeed-ingress + namespace: fed-librespeed spec: hosts: - - helloworld.<domain> + - librespeed.<domain> recordTTL: 300 ``` ```bash -$ kubectl --context=<host-cluster-context> create -f resource/ingressdnsrecord.yaml +$ kubectl --context=<host-cluster-context> create -f ingressDNSRecord/ingressdnsrecord.yaml ``` The name of IngressDNSRecord must be the same of the ingress resource and the value in "hosts" field must matches the "host" field in the ingress configuration. -- GitLab