|
| 1 | +--- |
| 2 | +title: TLS and DNS |
| 3 | +linktitle: TLS and DNS |
| 4 | +description: Automated TLS and DNS |
| 5 | +weight: 35 |
| 6 | +--- |
| 7 | + |
| 8 | +This section will describe how to enable automated TLS and DNS for your Jenkins X installation. |
| 9 | + |
| 10 | +To achive this we will use a couple of open source projects to help enable automated DNS for applications you |
| 11 | + |
| 12 | +For this guide we are going to assume you own a domain called `foo.io` which is managed by Google Cloud DNS, if it is not see [configure cloud dns to manage a domain](/docs/v3/guides/infra/google_cloud_dns). |
| 13 | + |
| 14 | +Jenkins X services will have URLs like `https://hook-jx.bar.foo.io`. The jx-requirement.yaml `namespaceSubDomain:` of `-jx` refers to the Kubernetes namespace the service is running in, this helps avoid clashes of the same application running in different namespaces in the same cluster. |
| 15 | + |
| 16 | +To start with we are focussed on GCP but will expand to other cloud providers. |
| 17 | + |
| 18 | +# Google Cloud Platform |
| 19 | + |
| 20 | +## Prerequisits |
| 21 | + |
| 22 | +- cluster created using Jenkins X [GCP Terraform getting started](/docs/v3/getting-started/gke/) |
| 23 | +- own a domain, we will use [Google Domains](https://domains.google.com/registrar/) in this guide but any provider will work |
| 24 | +- latest Jenkins X [upgrade](/docs/v3/guides/upgrade) |
| 25 | + |
| 26 | +### Cloud Infrastructure |
| 27 | +First we will configure the cloud infrastructure requirements: |
| 28 | + |
| 29 | +- a GCP Service Account with the `dns.admin` role, see [here](https://cloud.google.com/iam/docs/understanding-roles#dns-roles) for more information |
| 30 | +- a managed cloud dns zone, see [here](https://cloud.google.com/dns/docs/zones) for more information |
| 31 | + |
| 32 | +To satisfy these requirements go to your infrastructure repository (contains Terraform main.tf) and add to your `values.auto.tfvars` the following: |
| 33 | + |
| 34 | +```values.tf |
| 35 | +parent_domain = "foo.io" |
| 36 | +``` |
| 37 | + |
| 38 | +Most people prefer to use a subdomain for a specific installation rather than purchasing one domain per cluster. For example in a multi cluster setup you will probably want the same parent domain but each cluster using a differnt subdomain like development.foo.io, staging.foo.io and foo.io. |
| 39 | + |
| 40 | +To use a subdomain for this cluster add the following configuration: |
| 41 | + |
| 42 | +```values.tf |
| 43 | +subdomain = "bar" |
| 44 | +``` |
| 45 | + |
| 46 | +Now apply these changes: |
| 47 | + |
| 48 | +``` |
| 49 | +git add values.auto.tfvars |
| 50 | +git commit -m 'feat: enable DNS cloud resources' |
| 51 | +git push |
| 52 | +``` |
| 53 | + |
| 54 | +``` |
| 55 | +terraform plan |
| 56 | +terraform apply |
| 57 | +``` |
| 58 | + |
| 59 | +You can now see your managed zone in GCP [here](https://console.cloud.google.com/net-services/dns/zones) |
| 60 | + |
| 61 | + |
| 62 | +### Cluster |
| 63 | + |
| 64 | +Next we will configure the cluster requirements: |
| 65 | + |
| 66 | +- Install [external-dns](https://github.com/kubernetes-sigs/external-dns#externaldns) - Kubernetes controller which watches for new Kubernetes Ingress resources and creates A records in Google Cloud DNS which will propogate globally across the internet |
| 67 | +- Install [cert-manager](https://cert-manager.io/docs/) - Kuberbetes controller which watches for requests to ask [Let's Encrypt](https://letsencrypt.org/) to issue a new wildcard TLS certificate for your domain and will manage this including renewals |
| 68 | + |
| 69 | +To satisfy these requirements go to your cluster repository (contains helmfile.yaml) |
| 70 | + |
| 71 | +Add external-dns to your clusters helmfile.yaml `releases` section: |
| 72 | + |
| 73 | +``` |
| 74 | +- chart: bitnami/external-dns |
| 75 | +``` |
| 76 | + |
| 77 | +Add cert-manager to your clusters helmfile.yaml `releases` section: |
| 78 | +``` |
| 79 | +- chart: jetstack/cert-manager |
| 80 | +``` |
| 81 | + |
| 82 | +Next we install |
| 83 | +- a cluster wide [Issuer](https://cert-manager.io/docs/concepts/issuer/) which tells cert-manager how to validate you own your domain |
| 84 | +- a namespaced [Certificate](https://cert-manager.io/docs/concepts/certificate/) to request a TLS certificate for services running in the `jx` namespace |
| 85 | + |
| 86 | +``` |
| 87 | +- chart: jx3/acme |
| 88 | + name: tls-jx |
| 89 | + values: |
| 90 | + - issuer: |
| 91 | + enabled: true |
| 92 | + cluster: true |
| 93 | +``` |
| 94 | + |
| 95 | +Cert-manager will use the cluster issuer to request a TLS certificate for each namespaces [Certificate](https://cert-manager.io/docs/concepts/certificate/) found. The advantage here is that the same wildcard certificate is cached and reused for multiple namespaces reducing the risk of being [rate limited](https://letsencrypt.org/docs/rate-limits/) by Lets Encrypt. |
| 96 | + |
| 97 | +Now install the `acme` chart into any namespace you require TLS, e.g. |
| 98 | +``` |
| 99 | +- chart: jx3/acme |
| 100 | + name: tls-jx-staging |
| 101 | + namespace: jx-staging |
| 102 | +- chart: jx3/acme |
| 103 | + name: tls-jx-production |
| 104 | + namespace: jx-production |
| 105 | +``` |
| 106 | + |
| 107 | +The domain from setting up your infrastructure in step one should appear in the `jx-requirements.yaml` of you cluster git repo. Next configure your TLS options, update your `jx-requirements.yaml` with |
| 108 | +``` |
| 109 | +ingress: |
| 110 | + domain: bar.foo.io |
| 111 | + externalDNS: false # this is unused and will be deprecated |
| 112 | + namespaceSubDomain: -jx. |
| 113 | + tls: |
| 114 | + |
| 115 | + enabled: true |
| 116 | + production: false |
| 117 | +``` |
| 118 | + |
| 119 | +When first installing set `tls.production=false` so you use the Lets Encrtpt staging serivce which allows for more API calls before rate limniting requests. They will issue a self-signed certificate so once happy everything is working change this to `tls.production=true` |
| 120 | + |
| 121 | +Jenkins X uses a version stream to rollout tested versions of images, charts and default configuration. The `jx-boot` job will apply these versions to your helmfile but you can also run the step yourself to see the defaults. |
| 122 | + |
| 123 | +``` |
| 124 | +jx gitops helmfile resolve |
| 125 | +``` |
| 126 | + |
| 127 | +``` |
| 128 | +git add values.auto.tfvars |
| 129 | +git commit -m 'feat: enable DNS cloud resources' |
| 130 | +git push |
| 131 | +``` |
| 132 | + |
| 133 | +Now tail the admin logs and wait for the job to complete |
| 134 | +``` |
| 135 | +jx admin logs |
| 136 | +``` |
| 137 | + |
| 138 | +## How to get TLS in my preview environment? |
| 139 | + |
| 140 | +In your applications preview helm chart you can add a Kubernetes [Certificate](https://cert-manager.io/docs/concepts/certificate/) the same as in your `jx` namespace and cert-manager will create the secret needed by an Ingress rule for TLS. |
0 commit comments