sigs.k8s.io/external-dns@v0.14.1/docs/tutorials/ns1.md (about)

     1  # Setting up ExternalDNS for Services on NS1
     2  
     3  This tutorial describes how to setup ExternalDNS for use within a
     4  Kubernetes cluster using NS1 DNS.
     5  
     6  Make sure to use **>=0.5** version of ExternalDNS for this tutorial.
     7  
     8  ## Creating a zone with NS1 DNS
     9  
    10  If you are new to NS1, we recommend you first read the following
    11  instructions for creating a zone.
    12  
    13  [Creating a zone using the NS1
    14  portal](https://ns1.com/knowledgebase/creating-a-zone)
    15  
    16  [Creating a zone using the NS1
    17  API](https://ns1.com/api#put-create-a-new-dns-zone)
    18  
    19  ## Creating NS1 Credentials
    20  
    21  All NS1 products are API-first, meaning everything that can be done on
    22  the portal---including managing zones and records, data sources and
    23  feeds, and account settings and users---can be done via API.
    24  
    25  The NS1 API is a standard REST API with JSON responses. The environment
    26  var `NS1_APIKEY` will be needed to run ExternalDNS with NS1.
    27  
    28  ### To add or delete an API key
    29  
    30  1.  Log into the NS1 portal at [my.nsone.net](http://my.nsone.net).
    31  
    32  2.  Click your username in the upper-right corner, and navigate to **Account Settings** \> **Users & Teams**.
    33  
    34  3.  Navigate to the _API Keys_ tab, and click **Add Key**.
    35  
    36  4.  Enter the name of the application and modify permissions and settings as desired. Once complete, click **Create Key**. The new API key appears in the list.
    37  
    38      Note: Set the permissions for your API keys just as you would for a user or team associated with your organization's NS1 account. For more information, refer to the article [Creating and Managing API Keys](https://help.ns1.com/hc/en-us/articles/360026140094-Creating-managing-users) in the NS1 Knowledge Base.
    39  
    40  ## Deploy ExternalDNS
    41  
    42  Connect your `kubectl` client to the cluster with which you want to test ExternalDNS, and then apply one of the following manifest files for deployment:
    43  
    44  ### Manifest (for clusters without RBAC enabled)
    45  
    46  ```yaml
    47  apiVersion: apps/v1
    48  kind: Deployment
    49  metadata:
    50    name: external-dns
    51  spec:
    52    strategy:
    53      type: Recreate
    54    selector:
    55      matchLabels:
    56        app: external-dns
    57    template:
    58      metadata:
    59        labels:
    60          app: external-dns
    61      spec:
    62        containers:
    63        - name: external-dns
    64          image: registry.k8s.io/external-dns/external-dns:v0.14.0
    65          args:
    66          - --source=service # ingress is also possible
    67          - --domain-filter=example.com # (optional) limit to only example.com domains; change to match the zone created above.
    68          - --provider=ns1
    69          env:
    70          - name: NS1_APIKEY
    71            value: "YOUR_NS1_API_KEY"
    72  ```
    73  
    74  ### Manifest (for clusters with RBAC enabled)
    75  
    76  ```yaml
    77  apiVersion: v1
    78  kind: ServiceAccount
    79  metadata:
    80    name: external-dns
    81  ---
    82  apiVersion: rbac.authorization.k8s.io/v1
    83  kind: ClusterRole
    84  metadata:
    85    name: external-dns
    86  rules:
    87  - apiGroups: [""]
    88    resources: ["services","endpoints","pods"]
    89    verbs: ["get","watch","list"]
    90  - apiGroups: ["extensions","networking.k8s.io"]
    91    resources: ["ingresses"] 
    92    verbs: ["get","watch","list"]
    93  - apiGroups: [""]
    94    resources: ["nodes"]
    95    verbs: ["list"]
    96  ---
    97  apiVersion: rbac.authorization.k8s.io/v1
    98  kind: ClusterRoleBinding
    99  metadata:
   100    name: external-dns-viewer
   101  roleRef:
   102    apiGroup: rbac.authorization.k8s.io
   103    kind: ClusterRole
   104    name: external-dns
   105  subjects:
   106  - kind: ServiceAccount
   107    name: external-dns
   108    namespace: default
   109  ---
   110  apiVersion: apps/v1
   111  kind: Deployment
   112  metadata:
   113    name: external-dns
   114  spec:
   115    strategy:
   116      type: Recreate
   117    selector:
   118      matchLabels:
   119        app: external-dns
   120    template:
   121      metadata:
   122        labels:
   123          app: external-dns
   124      spec:
   125        serviceAccountName: external-dns
   126        containers:
   127        - name: external-dns
   128          image: registry.k8s.io/external-dns/external-dns:v0.14.0
   129          args:
   130          - --source=service # ingress is also possible
   131          - --domain-filter=example.com # (optional) limit to only example.com domains; change to match the zone created above.
   132          - --provider=ns1
   133          env:
   134          - name: NS1_APIKEY
   135            value: "YOUR_NS1_API_KEY"
   136  ```
   137  
   138  ## Deploying an Nginx Service
   139  
   140  Create a service file called 'nginx.yaml' with the following contents:
   141  
   142  ```yaml
   143  apiVersion: apps/v1
   144  kind: Deployment
   145  metadata:
   146    name: nginx
   147  spec:
   148    selector:
   149      matchLabels:
   150        app: nginx
   151    template:
   152      metadata:
   153        labels:
   154          app: nginx
   155      spec:
   156        containers:
   157        - image: nginx
   158          name: nginx
   159          ports:
   160          - containerPort: 80
   161  ---
   162  apiVersion: v1
   163  kind: Service
   164  metadata:
   165    name: nginx
   166    annotations:
   167      external-dns.alpha.kubernetes.io/hostname: example.com
   168      external-dns.alpha.kubernetes.io/ttl: "120" #optional
   169  spec:
   170    selector:
   171      app: nginx
   172    type: LoadBalancer
   173    ports:
   174      - protocol: TCP
   175        port: 80
   176        targetPort: 80
   177  ```
   178  
   179  **A note about annotations**
   180  
   181  Verify that the annotation on the service uses the same hostname as the NS1 DNS zone created above. The annotation may also be a subdomain of the DNS zone (e.g. 'www.example.com').
   182  
   183  The TTL annotation can be used to configure the TTL on DNS records managed by ExternalDNS and is optional. If this annotation is not set, the TTL on records managed by ExternalDNS will default to 10.
   184  
   185  ExternalDNS uses the hostname annotation to determine which services should be registered with DNS. Removing the hostname annotation will cause ExternalDNS to remove the corresponding DNS records.
   186  
   187  ### Create the deployment and service
   188  
   189  ```
   190  $ kubectl create -f nginx.yaml
   191  ```
   192  
   193  Depending on where you run your service, it may take some time for your cloud provider to create an external IP for the service. Once an external IP is assigned, ExternalDNS detects the new service IP address and synchronizes the NS1 DNS records.
   194  
   195  ## Verifying NS1 DNS records
   196  
   197  Use the NS1 portal or API to verify that the A record for your domain shows the external IP address of the services.
   198  
   199  ## Cleanup
   200  
   201  Once you successfully configure and verify record management via ExternalDNS, you can delete the tutorial's example:
   202  
   203  ```
   204  $ kubectl delete -f nginx.yaml
   205  $ kubectl delete -f externaldns.yaml
   206  ```