Convert site to Hugo (#8316)
This commit converts content and layout to use Hugo.
This commit is contained in:
committed by
k8s-ci-robot
parent
7745f0e0c5
commit
7f3b633aa0
@@ -0,0 +1,10 @@
|
||||
isClusterService: false
|
||||
serviceType: "LoadBalancer"
|
||||
middleware:
|
||||
kubernetes:
|
||||
enabled: false
|
||||
etcd:
|
||||
enabled: true
|
||||
zones:
|
||||
- "example.com."
|
||||
endpoint: "http://etcd-cluster.my-namespace:2379"
|
||||
Executable
+5
@@ -0,0 +1,5 @@
|
||||
---
|
||||
title: "Federation - Run an App on Multiple Clusters"
|
||||
weight: 120
|
||||
---
|
||||
|
||||
@@ -0,0 +1,385 @@
|
||||
---
|
||||
reviewers:
|
||||
- bprashanth
|
||||
- quinton-hoole
|
||||
title: Cross-cluster Service Discovery using Federated Services
|
||||
---
|
||||
|
||||
{{< include "federation-current-state.md" >}}
|
||||
|
||||
This guide explains how to use Kubernetes Federated Services to deploy
|
||||
a common Service across multiple Kubernetes clusters. This makes it
|
||||
easy to achieve cross-cluster service discovery and availability zone
|
||||
fault tolerance for your Kubernetes applications.
|
||||
|
||||
|
||||
{{< toc >}}
|
||||
|
||||
## Prerequisites
|
||||
|
||||
This guide assumes that you have a running Kubernetes Cluster
|
||||
Federation installation. If not, then head over to the
|
||||
[federation admin guide](/docs/admin/federation/) to learn how to
|
||||
bring up a cluster federation (or have your cluster administrator do
|
||||
this for you). Other tutorials, for example
|
||||
[this one](https://github.com/kelseyhightower/kubernetes-cluster-federation)
|
||||
by Kelsey Hightower, are also available to help you.
|
||||
|
||||
You are also expected to have a basic
|
||||
[working knowledge of Kubernetes](/docs/setup/) in
|
||||
general, and [Services](/docs/concepts/services-networking/service/) in particular.
|
||||
|
||||
## Overview
|
||||
|
||||
Federated Services are created in much that same way as traditional
|
||||
[Kubernetes Services](/docs/concepts/services-networking/service/) by making an API
|
||||
call which specifies the desired properties of your service. In the
|
||||
case of Federated Services, this API call is directed to the
|
||||
Federation API endpoint, rather than a Kubernetes cluster API
|
||||
endpoint. The API for Federated Services is 100% compatible with the
|
||||
API for traditional Kubernetes Services.
|
||||
|
||||
Once created, the Federated Service automatically:
|
||||
|
||||
1. Creates matching Kubernetes Services in every cluster underlying your Cluster Federation,
|
||||
2. Monitors the health of those service "shards" (and the clusters in which they reside), and
|
||||
3. Manages a set of DNS records in a public DNS provider (like Google Cloud DNS, or AWS Route 53), thus ensuring that clients
|
||||
of your federated service can seamlessly locate an appropriate healthy service endpoint at all times, even in the event of cluster,
|
||||
availability zone or regional outages.
|
||||
|
||||
Clients inside your federated Kubernetes clusters (i.e. Pods) will
|
||||
automatically find the local shard of the Federated Service in their
|
||||
cluster if it exists and is healthy, or the closest healthy shard in a
|
||||
different cluster if it does not.
|
||||
|
||||
## Hybrid cloud capabilities
|
||||
|
||||
Federations of Kubernetes Clusters can include clusters running in
|
||||
different cloud providers (e.g. Google Cloud, AWS), and on-premises
|
||||
(e.g. on OpenStack). Simply create all of the clusters that you
|
||||
require, in the appropriate cloud providers and/or locations, and
|
||||
register each cluster's API endpoint and credentials with your
|
||||
Federation API Server (See the
|
||||
[federation admin guide](/docs/admin/federation/) for details).
|
||||
|
||||
Thereafter, your applications and services can span different clusters
|
||||
and cloud providers as described in more detail below.
|
||||
|
||||
## Creating a federated service
|
||||
|
||||
This is done in the usual way, for example:
|
||||
|
||||
``` shell
|
||||
kubectl --context=federation-cluster create -f services/nginx.yaml
|
||||
```
|
||||
|
||||
The '--context=federation-cluster' flag tells kubectl to submit the
|
||||
request to the Federation API endpoint, with the appropriate
|
||||
credentials. If you have not yet configured such a context, visit the
|
||||
[federation admin guide](/docs/admin/federation/) or one of the
|
||||
[administration tutorials](https://github.com/kelseyhightower/kubernetes-cluster-federation)
|
||||
to find out how to do so.
|
||||
|
||||
As described above, the Federated Service will automatically create
|
||||
and maintain matching Kubernetes services in all of the clusters
|
||||
underlying your federation.
|
||||
|
||||
You can verify this by checking in each of the underlying clusters, for example:
|
||||
|
||||
``` shell
|
||||
kubectl --context=gce-asia-east1a get services nginx
|
||||
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
|
||||
nginx 10.63.250.98 104.199.136.89 80/TCP 9m
|
||||
```
|
||||
|
||||
The above assumes that you have a context named 'gce-asia-east1a'
|
||||
configured in your client for your cluster in that zone. The name and
|
||||
namespace of the underlying services will automatically match those of
|
||||
the Federated Service that you created above (and if you happen to
|
||||
have had services of the same name and namespace already existing in
|
||||
any of those clusters, they will be automatically adopted by the
|
||||
Federation and updated to conform with the specification of your
|
||||
Federated Service - either way, the end result will be the same).
|
||||
|
||||
The status of your Federated Service will automatically reflect the
|
||||
real-time status of the underlying Kubernetes services, for example:
|
||||
|
||||
``` shell
|
||||
$kubectl --context=federation-cluster describe services nginx
|
||||
|
||||
Name: nginx
|
||||
Namespace: default
|
||||
Labels: run=nginx
|
||||
Annotations: <none>
|
||||
Selector: run=nginx
|
||||
Type: LoadBalancer
|
||||
IP: 10.63.250.98
|
||||
LoadBalancer Ingress: 104.197.246.190, 130.211.57.243, 104.196.14.231, 104.199.136.89, ...
|
||||
Port: http 80/TCP
|
||||
Endpoints: <none>
|
||||
Session Affinity: None
|
||||
Events: <none>
|
||||
```
|
||||
|
||||
Note the 'LoadBalancer Ingress' addresses of your Federated Service
|
||||
correspond with the 'LoadBalancer Ingress' addresses of all of the
|
||||
underlying Kubernetes services (once these have been allocated - this
|
||||
may take a few seconds). For inter-cluster and inter-cloud-provider
|
||||
networking between service shards to work correctly, your services
|
||||
need to have an externally visible IP address. [Service Type:
|
||||
Loadbalancer](/docs/concepts/services-networking/service/#type-loadbalancer)
|
||||
is typically used for this, although other options
|
||||
(e.g. [External IP's](/docs/concepts/services-networking/service/#external-ips)) exist.
|
||||
|
||||
Note also that we have not yet provisioned any backend Pods to receive
|
||||
the network traffic directed to these addresses (i.e. 'Service
|
||||
Endpoints'), so the Federated Service does not yet consider these to
|
||||
be healthy service shards, and has accordingly not yet added their
|
||||
addresses to the DNS records for this Federated Service (more on this
|
||||
aspect later).
|
||||
|
||||
## Adding backend pods
|
||||
|
||||
To render the underlying service shards healthy, we need to add
|
||||
backend Pods behind them. This is currently done directly against the
|
||||
API endpoints of the underlying clusters (although in future the
|
||||
Federation server will be able to do all this for you with a single
|
||||
command, to save you the trouble). For example, to create backend Pods
|
||||
in 13 underlying clusters:
|
||||
|
||||
``` shell
|
||||
for CLUSTER in asia-east1-c asia-east1-a asia-east1-b \
|
||||
europe-west1-d europe-west1-c europe-west1-b \
|
||||
us-central1-f us-central1-a us-central1-b us-central1-c \
|
||||
us-east1-d us-east1-c us-east1-b
|
||||
do
|
||||
kubectl --context=$CLUSTER run nginx --image=nginx:1.11.1-alpine --port=80
|
||||
done
|
||||
```
|
||||
|
||||
Note that `kubectl run` automatically adds the `run=nginx` labels required to associate the backend pods with their services.
|
||||
|
||||
## Verifying public DNS records
|
||||
|
||||
Once the above Pods have successfully started and have begun listening
|
||||
for connections, Kubernetes will report them as healthy endpoints of
|
||||
the service in that cluster (via automatic health checks). The Cluster
|
||||
Federation will in turn consider each of these
|
||||
service 'shards' to be healthy, and place them in serving by
|
||||
automatically configuring corresponding public DNS records. You can
|
||||
use your preferred interface to your configured DNS provider to verify
|
||||
this. For example, if your Federation is configured to use Google
|
||||
Cloud DNS, and a managed DNS domain 'example.com':
|
||||
|
||||
``` shell
|
||||
$ gcloud dns managed-zones describe example-dot-com
|
||||
creationTime: '2016-06-26T18:18:39.229Z'
|
||||
description: Example domain for Kubernetes Cluster Federation
|
||||
dnsName: example.com.
|
||||
id: '3229332181334243121'
|
||||
kind: dns#managedZone
|
||||
name: example-dot-com
|
||||
nameServers:
|
||||
- ns-cloud-a1.googledomains.com.
|
||||
- ns-cloud-a2.googledomains.com.
|
||||
- ns-cloud-a3.googledomains.com.
|
||||
- ns-cloud-a4.googledomains.com.
|
||||
```
|
||||
|
||||
``` shell
|
||||
$ gcloud dns record-sets list --zone example-dot-com
|
||||
NAME TYPE TTL DATA
|
||||
example.com. NS 21600 ns-cloud-e1.googledomains.com., ns-cloud-e2.googledomains.com.
|
||||
example.com. OA 21600 ns-cloud-e1.googledomains.com. cloud-dns-hostmaster.google.com. 1 21600 3600 1209600 300
|
||||
nginx.mynamespace.myfederation.svc.example.com. A 180 104.197.246.190, 130.211.57.243, 104.196.14.231, 104.199.136.89,...
|
||||
nginx.mynamespace.myfederation.svc.us-central1-a.example.com. A 180 104.197.247.191
|
||||
nginx.mynamespace.myfederation.svc.us-central1-b.example.com. A 180 104.197.244.180
|
||||
nginx.mynamespace.myfederation.svc.us-central1-c.example.com. A 180 104.197.245.170
|
||||
nginx.mynamespace.myfederation.svc.us-central1-f.example.com. CNAME 180 nginx.mynamespace.myfederation.svc.us-central1.example.com.
|
||||
nginx.mynamespace.myfederation.svc.us-central1.example.com. A 180 104.197.247.191, 104.197.244.180, 104.197.245.170
|
||||
nginx.mynamespace.myfederation.svc.asia-east1-a.example.com. A 180 130.211.57.243
|
||||
nginx.mynamespace.myfederation.svc.asia-east1-b.example.com. CNAME 180 nginx.mynamespace.myfederation.svc.asia-east1.example.com.
|
||||
nginx.mynamespace.myfederation.svc.asia-east1-c.example.com. A 180 130.211.56.221
|
||||
nginx.mynamespace.myfederation.svc.asia-east1.example.com. A 180 130.211.57.243, 130.211.56.221
|
||||
nginx.mynamespace.myfederation.svc.europe-west1.example.com. CNAME 180 nginx.mynamespace.myfederation.svc.example.com.
|
||||
nginx.mynamespace.myfederation.svc.europe-west1-d.example.com. CNAME 180 nginx.mynamespace.myfederation.svc.europe-west1.example.com.
|
||||
... etc.
|
||||
```
|
||||
|
||||
Note: If your Federation is configured to use AWS Route53, you can use one of the equivalent AWS tools, for example:
|
||||
|
||||
``` shell
|
||||
$ aws route53 list-hosted-zones
|
||||
```
|
||||
and
|
||||
|
||||
``` shell
|
||||
$ aws route53 list-resource-record-sets --hosted-zone-id Z3ECL0L9QLOVBX
|
||||
```
|
||||
|
||||
Whatever DNS provider you use, any DNS query tool (for example 'dig'
|
||||
or 'nslookup') will of course also allow you to see the records
|
||||
created by the Federation for you. Note that you should either point
|
||||
these tools directly at your DNS provider (e.g. `dig
|
||||
@ns-cloud-e1.googledomains.com...`) or expect delays in the order of
|
||||
your configured TTL (180 seconds, by default) before seeing updates,
|
||||
due to caching by intermediate DNS servers.
|
||||
|
||||
### Some notes about the above example
|
||||
|
||||
1. Notice that there is a normal ('A') record for each service shard that has at least one healthy backend endpoint. For example, in us-central1-a, 104.197.247.191 is the external IP address of the service shard in that zone, and in asia-east1-a the address is 130.211.56.221.
|
||||
2. Similarly, there are regional 'A' records which include all healthy shards in that region. For example, 'us-central1'. These regional records are useful for clients which do not have a particular zone preference, and as a building block for the automated locality and failover mechanism described below.
|
||||
3. For zones where there are currently no healthy backend endpoints, a CNAME ('Canonical Name') record is used to alias (automatically redirect) those queries to the next closest healthy zone. In the example, the service shard in us-central1-f currently has no healthy backend endpoints (i.e. Pods), so a CNAME record has been created to automatically redirect queries to other shards in that region (us-central1 in this case).
|
||||
4. Similarly, if no healthy shards exist in the enclosing region, the search progresses further afield. In the europe-west1-d availability zone, there are no healthy backends, so queries are redirected to the broader europe-west1 region (which also has no healthy backends), and onward to the global set of healthy addresses (' nginx.mynamespace.myfederation.svc.example.com.').
|
||||
|
||||
The above set of DNS records is automatically kept in sync with the
|
||||
current state of health of all service shards globally by the
|
||||
Federated Service system. DNS resolver libraries (which are invoked by
|
||||
all clients) automatically traverse the hierarchy of 'CNAME' and 'A'
|
||||
records to return the correct set of healthy IP addresses. Clients can
|
||||
then select any one of the returned addresses to initiate a network
|
||||
connection (and fail over automatically to one of the other equivalent
|
||||
addresses if required).
|
||||
|
||||
## Discovering a federated service
|
||||
|
||||
### From pods inside your federated clusters
|
||||
|
||||
By default, Kubernetes clusters come pre-configured with a
|
||||
cluster-local DNS server ('KubeDNS'), as well as an intelligently
|
||||
constructed DNS search path which together ensure that DNS queries
|
||||
like "myservice", "myservice.mynamespace",
|
||||
"bobsservice.othernamespace" etc issued by your software running
|
||||
inside Pods are automatically expanded and resolved correctly to the
|
||||
appropriate service IP of services running in the local cluster.
|
||||
|
||||
With the introduction of Federated Services and Cross-Cluster Service
|
||||
Discovery, this concept is extended to cover Kubernetes services
|
||||
running in any other cluster across your Cluster Federation, globally.
|
||||
To take advantage of this extended range, you use a slightly different
|
||||
DNS name (of the form "<servicename>.<namespace>.<federationname>",
|
||||
e.g. myservice.mynamespace.myfederation) to resolve Federated
|
||||
Services. Using a different DNS name also avoids having your existing
|
||||
applications accidentally traversing cross-zone or cross-region
|
||||
networks and you incurring perhaps unwanted network charges or
|
||||
latency, without you explicitly opting in to this behavior.
|
||||
|
||||
So, using our NGINX example service above, and the Federated Service
|
||||
DNS name form just described, let's consider an example: A Pod in a
|
||||
cluster in the `us-central1-f` availability zone needs to contact our
|
||||
NGINX service. Rather than use the service's traditional cluster-local
|
||||
DNS name (```"nginx.mynamespace"```, which is automatically expanded
|
||||
to ```"nginx.mynamespace.svc.cluster.local"```) it can now use the
|
||||
service's Federated DNS name, which is
|
||||
```"nginx.mynamespace.myfederation"```. This will be automatically
|
||||
expanded and resolved to the closest healthy shard of my NGINX
|
||||
service, wherever in the world that may be. If a healthy shard exists
|
||||
in the local cluster, that service's cluster-local (typically
|
||||
10.x.y.z) IP address will be returned (by the cluster-local KubeDNS).
|
||||
This is almost exactly equivalent to non-federated service resolution
|
||||
(almost because KubeDNS actually returns both a CNAME and an A record
|
||||
for local federated services, but applications will be oblivious
|
||||
to this minor technical difference).
|
||||
|
||||
But if the service does not exist in the local cluster (or it exists
|
||||
but has no healthy backend pods), the DNS query is automatically
|
||||
expanded to ```"nginx.mynamespace.myfederation.svc.us-central1-f.example.com"```
|
||||
(i.e. logically "find the external IP of one of the shards closest to
|
||||
my availability zone"). This expansion is performed automatically by
|
||||
KubeDNS, which returns the associated CNAME record. This results in
|
||||
automatic traversal of the hierarchy of DNS records in the above
|
||||
example, and ends up at one of the external IP's of the Federated
|
||||
Service in the local us-central1 region (i.e. 104.197.247.191,
|
||||
104.197.244.180 or 104.197.245.170).
|
||||
|
||||
It is of course possible to explicitly target service shards in
|
||||
availability zones and regions other than the ones local to a Pod by
|
||||
specifying the appropriate DNS names explicitly, and not relying on
|
||||
automatic DNS expansion. For example,
|
||||
"nginx.mynamespace.myfederation.svc.europe-west1.example.com" will
|
||||
resolve to all of the currently healthy service shards in Europe, even
|
||||
if the Pod issuing the lookup is located in the U.S., and irrespective
|
||||
of whether or not there are healthy shards of the service in the U.S.
|
||||
This is useful for remote monitoring and other similar applications.
|
||||
|
||||
### From other clients outside your federated clusters
|
||||
|
||||
Much of the above discussion applies equally to external clients,
|
||||
except that the automatic DNS expansion described is no longer
|
||||
possible. So external clients need to specify one of the fully
|
||||
qualified DNS names of the Federated Service, be that a zonal,
|
||||
regional or global name. For convenience reasons, it is often a good
|
||||
idea to manually configure additional static CNAME records in your
|
||||
service, for example:
|
||||
|
||||
``` shell
|
||||
eu.nginx.acme.com CNAME nginx.mynamespace.myfederation.svc.europe-west1.example.com.
|
||||
us.nginx.acme.com CNAME nginx.mynamespace.myfederation.svc.us-central1.example.com.
|
||||
nginx.acme.com CNAME nginx.mynamespace.myfederation.svc.example.com.
|
||||
```
|
||||
That way your clients can always use the short form on the left, and
|
||||
always be automatically routed to the closest healthy shard on their
|
||||
home continent. All of the required failover is handled for you
|
||||
automatically by Kubernetes Cluster Federation. Future releases will
|
||||
improve upon this even further.
|
||||
|
||||
## Handling failures of backend pods and whole clusters
|
||||
|
||||
Standard Kubernetes service cluster-IP's already ensure that
|
||||
non-responsive individual Pod endpoints are automatically taken out of
|
||||
service with low latency (a few seconds). In addition, as alluded
|
||||
above, the Kubernetes Cluster Federation system automatically monitors
|
||||
the health of clusters and the endpoints behind all of the shards of
|
||||
your Federated Service, taking shards in and out of service as
|
||||
required (e.g. when all of the endpoints behind a service, or perhaps
|
||||
the entire cluster or availability zone go down, or conversely recover
|
||||
from an outage). Due to the latency inherent in DNS caching (the cache
|
||||
timeout, or TTL for Federated Service DNS records is configured to 3
|
||||
minutes, by default, but can be adjusted), it may take up to that long
|
||||
for all clients to completely fail over to an alternative cluster in
|
||||
the case of catastrophic failure. However, given the number of
|
||||
discrete IP addresses which can be returned for each regional service
|
||||
endpoint (see e.g. us-central1 above, which has three alternatives)
|
||||
many clients will fail over automatically to one of the alternative
|
||||
IP's in less time than that given appropriate configuration.
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
#### I cannot connect to my cluster federation API
|
||||
Check that your
|
||||
|
||||
1. Client (typically kubectl) is correctly configured (including API endpoints and login credentials).
|
||||
2. Cluster Federation API server is running and network-reachable.
|
||||
|
||||
See the [federation admin guide](/docs/admin/federation/) to learn
|
||||
how to bring up a cluster federation correctly (or have your cluster administrator do this for you), and how to correctly configure your client.
|
||||
|
||||
#### I can create a federated service successfully against the cluster federation API, but no matching services are created in my underlying clusters
|
||||
Check that:
|
||||
|
||||
1. Your clusters are correctly registered in the Cluster Federation API (`kubectl describe clusters`).
|
||||
2. Your clusters are all 'Active'. This means that the cluster Federation system was able to connect and authenticate against the clusters' endpoints. If not, consult the logs of the federation-controller-manager pod to ascertain what the failure might be.
|
||||
```kubectl --namespace=federation logs $(kubectl get pods --namespace=federation -l module=federation-controller-manager -o name)```
|
||||
3. That the login credentials provided to the Cluster Federation API for the clusters have the correct authorization and quota to create services in the relevant namespace in the clusters. Again you should see associated error messages providing more detail in the above log file if this is not the case.
|
||||
4. Whether any other error is preventing the service creation operation from succeeding (look for `service-controller` errors in the output of `kubectl logs federation-controller-manager --namespace federation`).
|
||||
|
||||
#### I can create a federated service successfully, but no matching DNS records are created in my DNS provider.
|
||||
Check that:
|
||||
|
||||
1. Your federation name, DNS provider, DNS domain name are configured correctly. Consult the [federation admin guide](/docs/admin/federation/) or [tutorial](https://github.com/kelseyhightower/kubernetes-cluster-federation) to learn
|
||||
how to configure your Cluster Federation system's DNS provider (or have your cluster administrator do this for you).
|
||||
2. Confirm that the Cluster Federation's service-controller is successfully connecting to and authenticating against your selected DNS provider (look for `service-controller` errors or successes in the output of `kubectl logs federation-controller-manager --namespace federation`).
|
||||
3. Confirm that the Cluster Federation's service-controller is successfully creating DNS records in your DNS provider (or outputting errors in its logs explaining in more detail what's failing).
|
||||
|
||||
#### Matching DNS records are created in my DNS provider, but clients are unable to resolve against those names
|
||||
Check that:
|
||||
|
||||
1. The DNS registrar that manages your federation DNS domain has been correctly configured to point to your configured DNS provider's nameservers. See for example [Google Domains Documentation](https://support.google.com/domains/answer/3290309?hl=en&ref_topic=3251230) and [Google Cloud DNS Documentation](https://cloud.google.com/dns/update-name-servers), or equivalent guidance from your domain registrar and DNS provider.
|
||||
|
||||
#### This troubleshooting guide did not help me solve my problem
|
||||
|
||||
1. Please use one of our [support channels](/docs/tasks/debug-application-cluster/troubleshooting/) to seek assistance.
|
||||
|
||||
## For more information
|
||||
|
||||
* [Federation proposal](https://git.k8s.io/community/contributors/design-proposals/multicluster/federation.md) details use cases that motivated this work.
|
||||
@@ -0,0 +1,34 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
labels:
|
||||
app: opa
|
||||
name: opa
|
||||
namespace: federation-system
|
||||
spec:
|
||||
replicas: 1
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: opa
|
||||
name: opa
|
||||
spec:
|
||||
containers:
|
||||
- name: opa
|
||||
image: openpolicyagent/opa:0.4.10
|
||||
args:
|
||||
- "run"
|
||||
- "--server"
|
||||
- name: kube-mgmt
|
||||
image: openpolicyagent/kube-mgmt:0.2
|
||||
args:
|
||||
- "-kubeconfig=/srv/kubernetes/kubeconfig"
|
||||
- "-cluster=federation/v1beta1/clusters"
|
||||
volumeMounts:
|
||||
- name: federation-kubeconfig
|
||||
mountPath: /srv/kubernetes
|
||||
readOnly: true
|
||||
volumes:
|
||||
- name: federation-kubeconfig
|
||||
secret:
|
||||
secretName: federation-controller-manager-kubeconfig
|
||||
@@ -0,0 +1,13 @@
|
||||
kind: Service
|
||||
apiVersion: v1
|
||||
metadata:
|
||||
name: opa
|
||||
namespace: federation-system
|
||||
spec:
|
||||
selector:
|
||||
app: opa
|
||||
ports:
|
||||
- name: http
|
||||
protocol: TCP
|
||||
port: 8181
|
||||
targetPort: 8181
|
||||
@@ -0,0 +1,74 @@
|
||||
# OPA supports a high-level declarative language named Rego for authoring and
|
||||
# enforcing policies. For more infomration on Rego, visit
|
||||
# http://openpolicyagent.org.
|
||||
|
||||
# Rego policies are namespaced by the "package" directive.
|
||||
package kubernetes.placement
|
||||
|
||||
# Imports provide aliases for data inside the policy engine. In this case, the
|
||||
# policy simply refers to "clusters" below.
|
||||
import data.kubernetes.clusters
|
||||
|
||||
# The "annotations" rule generates a JSON object containing the key
|
||||
# "federation.kubernetes.io/replica-set-preferences" mapped to <preferences>.
|
||||
# The preferences values is generated dynamically by OPA when it evaluates the
|
||||
# rule.
|
||||
#
|
||||
# The SchedulingPolicy Admission Controller running inside the Federation API
|
||||
# server will merge these annotatiosn into incoming Federated resources. By
|
||||
# setting replica-set-preferences, we can control the placement of Federated
|
||||
# ReplicaSets.
|
||||
#
|
||||
# Rules are defined to generate JSON values (booleans, strings, objects, etc.)
|
||||
# When OPA evaluates a rule, it generates a value IF all of the expressions in
|
||||
# the body evaluate successfully. All rules can be understood intuitively as
|
||||
# <head> if <body> where <body> is true if <expr-1> AND <expr-2> AND ...
|
||||
# <expr-N> is true (for some set of data.)
|
||||
annotations["federation.kubernetes.io/replica-set-preferences"] = preferences {
|
||||
input.kind = "ReplicaSet"
|
||||
value = {"clusters": cluster_map, "rebalance": true}
|
||||
json.marshal(value, preferences)
|
||||
}
|
||||
|
||||
# This "annotations" rule generates a value for the "federation.alpha.kubernetes.io/cluster-selector"
|
||||
# annotation.
|
||||
#
|
||||
# In English, the policy asserts that resources in the "production" namespace
|
||||
# that are not annotated with "criticality=low" MUST be placed on clusters
|
||||
# labelled with "on-premises=true".
|
||||
annotations["federation.alpha.kubernetes.io/cluster-selector"] = selector {
|
||||
input.metadata.namespace = "production"
|
||||
not input.metadata.annotations.criticality = "low"
|
||||
json.marshal([{
|
||||
"operator": "=",
|
||||
"key": "on-premises",
|
||||
"values": "[true]",
|
||||
}], selector)
|
||||
}
|
||||
|
||||
# Generates a set of cluster names that satisfy the incoming Federated
|
||||
# ReplicaSet's requirements. In this case, just PCI compliance.
|
||||
replica_set_clusters[cluster_name] {
|
||||
clusters[cluster_name]
|
||||
not insufficient_pci[cluster_name]
|
||||
}
|
||||
|
||||
# Generates a set of clusters that must not be used for Federated ReplicaSets
|
||||
# that request PCI compliance.
|
||||
insufficient_pci[cluster_name] {
|
||||
clusters[cluster_name]
|
||||
input.metadata.annotations["requires-pci"] = "true"
|
||||
not pci_clusters[cluster_name]
|
||||
}
|
||||
|
||||
# Generates a set of clusters that are PCI certified. In this case, we assume
|
||||
# clusters are annotated to indicate if they have passed PCI compliance audits.
|
||||
pci_clusters[cluster_name] {
|
||||
clusters[cluster_name].metadata.annotations["pci-certified"] = "true"
|
||||
}
|
||||
|
||||
# Helper rule to generate a mapping of desired clusters to weights. In this
|
||||
# case, weights are static.
|
||||
cluster_map[cluster_name] = {"weight": 1} {
|
||||
replica_set_clusters[cluster_name]
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
apiVersion: apps/v1
|
||||
kind: ReplicaSet
|
||||
metadata:
|
||||
labels:
|
||||
app: nginx-pci
|
||||
name: nginx-pci
|
||||
annotations:
|
||||
requires-pci: "true"
|
||||
spec:
|
||||
replicas: 3
|
||||
selector:
|
||||
matchLabels:
|
||||
app: nginx-pci
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: nginx-pci
|
||||
spec:
|
||||
containers:
|
||||
- image: nginx
|
||||
name: nginx-pci
|
||||
@@ -0,0 +1,29 @@
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: admission
|
||||
namespace: federation-system
|
||||
data:
|
||||
config.yml: |
|
||||
apiVersion: apiserver.k8s.io/v1alpha1
|
||||
kind: AdmissionConfiguration
|
||||
plugins:
|
||||
- name: SchedulingPolicy
|
||||
path: /etc/kubernetes/admission/scheduling-policy-config.yml
|
||||
scheduling-policy-config.yml: |
|
||||
kubeconfig: /etc/kubernetes/admission/opa-kubeconfig
|
||||
opa-kubeconfig: |
|
||||
clusters:
|
||||
- name: opa-api
|
||||
cluster:
|
||||
server: http://opa.federation-system.svc.cluster.local:8181/v0/data/kubernetes/placement
|
||||
users:
|
||||
- name: scheduling-policy
|
||||
user:
|
||||
token: deadbeefsecret
|
||||
contexts:
|
||||
- name: default
|
||||
context:
|
||||
cluster: opa-api
|
||||
user: scheduling-policy
|
||||
current-context: default
|
||||
@@ -0,0 +1,533 @@
|
||||
---
|
||||
reviewers:
|
||||
- madhusudancs
|
||||
title: Set up Cluster Federation with Kubefed
|
||||
---
|
||||
|
||||
{{< include "federation-current-state.md" >}}
|
||||
|
||||
{{< toc >}}
|
||||
|
||||
Kubernetes version 1.5 and above includes a new command line tool called
|
||||
[`kubefed`](/docs/admin/kubefed/) to help you administrate your federated
|
||||
clusters. `kubefed` helps you to deploy a new Kubernetes cluster federation
|
||||
control plane, and to add clusters to or remove clusters from an existing
|
||||
federation control plane.
|
||||
|
||||
This guide explains how to administer a Kubernetes Cluster Federation
|
||||
using `kubefed`.
|
||||
|
||||
> Note: `kubefed` is a beta feature in Kubernetes 1.6.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
This guide assumes that you have a running Kubernetes cluster. Please
|
||||
see one of the [getting started](/docs/setup/) guides
|
||||
for installation instructions for your platform.
|
||||
|
||||
## Getting `kubefed`
|
||||
|
||||
Download the client tarball corresponding to the particular release and
|
||||
extract the binaries in the tarball:
|
||||
|
||||
> Note that until kubernetes versions `1.8.x` the federation project was
|
||||
maintained as part of [core kubernetes repo](https://github.com/kubernetes/kubernetes).
|
||||
At some point between kubernetes releases `1.8.0` and `1.9.0`, it moved into
|
||||
a separate [federation repo](https://github.com/kubernetes/federation) and is
|
||||
now maintained there. After this move, the federation release information is
|
||||
available at the release page [here](https://github.com/kubernetes/federation/releases).
|
||||
|
||||
### For k8s versions 1.8.x and earlier:
|
||||
|
||||
```shell
|
||||
curl -LO https://storage.googleapis.com/kubernetes-release/release/${RELEASE-VERSION}/kubernetes-client-linux-amd64.tar.gz
|
||||
tar -xzvf kubernetes-client-linux-amd64.tar.gz
|
||||
```
|
||||
> Note that the variable `RELEASE-VERSION` should be either appropriately
|
||||
set to or replaced with the actual version needed.
|
||||
|
||||
Copy the extracted binary to one of the directories in your `$PATH`
|
||||
and set the executable permission on the binary.
|
||||
|
||||
```shell
|
||||
sudo cp kubernetes/client/bin/kubefed /usr/local/bin
|
||||
sudo chmod +x /usr/local/bin/kubefed
|
||||
```
|
||||
|
||||
### For k8s versions 1.9.x and above:
|
||||
|
||||
```shell
|
||||
curl -LO https://storage.cloud.google.com/kubernetes-federation-release/release/${RELEASE-VERSION}/federation-client-linux-amd64.tar.gz
|
||||
tar -xzvf federation-client-linux-amd64.tar.gz
|
||||
```
|
||||
|
||||
> Note that the variable `RELEASE-VERSION` should be replaced with one of the
|
||||
release versions available at [federation release page](https://github.com/kubernetes/federation/releases).
|
||||
|
||||
Copy the extracted binary to one of the directories in your `$PATH`
|
||||
and set the executable permission on the binary.
|
||||
|
||||
```shell
|
||||
sudo cp federation/client/bin/kubefed /usr/local/bin
|
||||
sudo chmod +x /usr/local/bin/kubefed
|
||||
```
|
||||
|
||||
### Install kubectl
|
||||
|
||||
You can install a matching version of kubectl using the instructions on
|
||||
the [kubectl install page](https://kubernetes.io/docs/tasks/tools/install-kubectl/).
|
||||
|
||||
## Choosing a host cluster.
|
||||
|
||||
You'll need to choose one of your Kubernetes clusters to be the
|
||||
*host cluster*. The host cluster hosts the components that make up
|
||||
your federation control plane. Ensure that you have a `kubeconfig`
|
||||
entry in your local `kubeconfig` that corresponds to the host cluster.
|
||||
You can verify that you have the required `kubeconfig` entry by
|
||||
running:
|
||||
|
||||
```shell
|
||||
kubectl config get-contexts
|
||||
```
|
||||
|
||||
The output should contain an entry corresponding to your host cluster,
|
||||
similar to the following:
|
||||
|
||||
```
|
||||
CURRENT NAME CLUSTER AUTHINFO NAMESPACE
|
||||
* gke_myproject_asia-east1-b_gce-asia-east1 gke_myproject_asia-east1-b_gce-asia-east1 gke_myproject_asia-east1-b_gce-asia-east1
|
||||
```
|
||||
|
||||
|
||||
You'll need to provide the `kubeconfig` context (called name in the
|
||||
entry above) for your host cluster when you deploy your federation
|
||||
control plane.
|
||||
|
||||
|
||||
## Deploying a federation control plane
|
||||
|
||||
To deploy a federation control plane on your host cluster, run
|
||||
[`kubefed init`](/docs/admin/kubefed_init/) command. When you use
|
||||
`kubefed init`, you must provide the following:
|
||||
|
||||
* Federation name
|
||||
* `--host-cluster-context`, the `kubeconfig` context for the host cluster
|
||||
* `--dns-provider`, one of `'google-clouddns'`, `aws-route53` or `coredns`
|
||||
* `--dns-zone-name`, a domain name suffix for your federated services
|
||||
|
||||
If your host cluster is running in a non-cloud environment or an
|
||||
environment that doesn't support common cloud primitives such as
|
||||
load balancers, you might need additional flags. Please see the
|
||||
[on-premises host clusters](#on-premises-host-clusters) section below.
|
||||
|
||||
The following example command deploys a federation control plane with
|
||||
the name `fellowship`, a host cluster context `rivendell`, and the
|
||||
domain suffix `example.com.`:
|
||||
|
||||
```shell
|
||||
kubefed init fellowship \
|
||||
--host-cluster-context=rivendell \
|
||||
--dns-provider="google-clouddns" \
|
||||
--dns-zone-name="example.com."
|
||||
```
|
||||
|
||||
The domain suffix specified in `--dns-zone-name` must be an existing
|
||||
domain that you control, and that is programmable by your DNS provider.
|
||||
It must also end with a trailing dot.
|
||||
|
||||
Once the federation control plane is initialized, query the namespaces:
|
||||
|
||||
```shell
|
||||
kubectl get namespace --context=fellowship
|
||||
```
|
||||
|
||||
If you do not see the `default` namespace listed (this is due to a
|
||||
[bug](https://github.com/kubernetes/kubernetes/issues/33292)). Create it
|
||||
yourself with the following command:
|
||||
|
||||
```shell
|
||||
kubectl create namespace default --context=fellowship
|
||||
```
|
||||
|
||||
The machines in your host cluster must have the appropriate permissions
|
||||
to program the DNS service that you are using. For example, if your
|
||||
cluster is running on Google Compute Engine, you must enable the
|
||||
Google Cloud DNS API for your project.
|
||||
|
||||
The machines in Google Kubernetes Engine clusters are created
|
||||
without the Google Cloud DNS API scope by default. If you want to use a
|
||||
Google Kubernetes Engine cluster as a Federation host, you must create it using the `gcloud`
|
||||
command with the appropriate value in the `--scopes` field. You cannot
|
||||
modify a Google Kubernetes Engine cluster directly to add this scope, but you can create a
|
||||
new node pool for your cluster and delete the old one. *Note that this
|
||||
will cause pods in the cluster to be rescheduled.*
|
||||
|
||||
To add the new node pool, run:
|
||||
|
||||
```shell
|
||||
scopes="$(gcloud container node-pools describe --cluster=gke-cluster default-pool --format='value[delimiter=","](config.oauthScopes)')"
|
||||
gcloud container node-pools create new-np \
|
||||
--cluster=gke-cluster \
|
||||
--scopes="${scopes},https://www.googleapis.com/auth/ndev.clouddns.readwrite"
|
||||
```
|
||||
|
||||
To delete the old node pool, run:
|
||||
|
||||
```shell
|
||||
gcloud container node-pools delete default-pool --cluster gke-cluster
|
||||
```
|
||||
|
||||
`kubefed init` sets up the federation control plane in the host
|
||||
cluster and also adds an entry for the federation API server in your
|
||||
local kubeconfig. Note that in the beta release in Kubernetes 1.6,
|
||||
`kubefed init` does not automatically set the current context to the
|
||||
newly deployed federation. You can set the current context manually by
|
||||
running:
|
||||
|
||||
```shell
|
||||
kubectl config use-context fellowship
|
||||
```
|
||||
|
||||
where `fellowship` is the name of your federation.
|
||||
|
||||
### Basic and token authentication support
|
||||
|
||||
`kubefed init` by default only generates TLS certificates and keys
|
||||
to authenticate with the federation API server and writes them to
|
||||
your local kubeconfig file. If you wish to enable basic authentication
|
||||
or token authentication for debugging purposes, you can enable them by
|
||||
passing the `--apiserver-enable-basic-auth` flag or the
|
||||
`--apiserver-enable-token-auth` flag.
|
||||
|
||||
```shell
|
||||
kubefed init fellowship \
|
||||
--host-cluster-context=rivendell \
|
||||
--dns-provider="google-clouddns" \
|
||||
--dns-zone-name="example.com." \
|
||||
--apiserver-enable-basic-auth=true \
|
||||
--apiserver-enable-token-auth=true
|
||||
```
|
||||
|
||||
### Passing command line arguments to federation components
|
||||
|
||||
`kubefed init` bootstraps a federation control plane with default
|
||||
arguments to federation API server and federation controller manager.
|
||||
Some of these arguments are derived from `kubefed init`'s flags.
|
||||
However, you can override these command line arguments by passing
|
||||
them via the appropriate override flags.
|
||||
|
||||
You can override the federation API server arguments by passing them
|
||||
to `--apiserver-arg-overrides` and override the federation controller
|
||||
manager arguments by passing them to
|
||||
`--controllermanager-arg-overrides`.
|
||||
|
||||
```shell
|
||||
kubefed init fellowship \
|
||||
--host-cluster-context=rivendell \
|
||||
--dns-provider="google-clouddns" \
|
||||
--dns-zone-name="example.com." \
|
||||
--apiserver-arg-overrides="--anonymous-auth=false,--v=4" \
|
||||
--controllermanager-arg-overrides="--controllers=services=false"
|
||||
```
|
||||
|
||||
### Configuring a DNS provider
|
||||
|
||||
The Federated service controller programs a DNS provider to expose
|
||||
federated services via DNS names. Certain cloud providers
|
||||
automatically provide the configuration required to program the
|
||||
DNS provider if the host cluster's cloud provider is same as the DNS
|
||||
provider. In all other cases, you have to provide the DNS provider
|
||||
configuration to your federation controller manager which will in-turn
|
||||
be passed to the federated service controller. You can provide this
|
||||
configuration to federation controller manager by storing it in a file
|
||||
and passing the file's local filesystem path to `kubefed init`'s
|
||||
`--dns-provider-config` flag. For example, save the config below in
|
||||
`$HOME/coredns-provider.conf`.
|
||||
|
||||
```ini
|
||||
[Global]
|
||||
etcd-endpoints = http://etcd-cluster.ns:2379
|
||||
zones = example.com.
|
||||
```
|
||||
|
||||
And then pass this file to `kubefed init`:
|
||||
|
||||
```shell
|
||||
kubefed init fellowship \
|
||||
--host-cluster-context=rivendell \
|
||||
--dns-provider="coredns" \
|
||||
--dns-zone-name="example.com." \
|
||||
--dns-provider-config="$HOME/coredns-provider.conf"
|
||||
```
|
||||
|
||||
### On-premises host clusters
|
||||
|
||||
#### API server service type
|
||||
|
||||
`kubefed init` exposes the federation API server as a Kubernetes
|
||||
[service](/docs/concepts/services-networking/service/) on the host cluster. By default,
|
||||
this service is exposed as a
|
||||
[load balanced service](/docs/concepts/services-networking/service/#type-loadbalancer).
|
||||
Most on-premises and bare-metal environments, and some cloud
|
||||
environments lack support for load balanced services. `kubefed init`
|
||||
allows exposing the federation API server as a
|
||||
[`NodePort` service](/docs/concepts/services-networking/service/#type-nodeport) on
|
||||
such environments. This can be accomplished by passing
|
||||
the `--api-server-service-type=NodePort` flag. You can also specify
|
||||
the preferred address to advertise the federation API server by
|
||||
passing the `--api-server-advertise-address=<IP-address>`
|
||||
flag. Otherwise, one of the host cluster's node address is chosen as
|
||||
the default.
|
||||
|
||||
```shell
|
||||
kubefed init fellowship \
|
||||
--host-cluster-context=rivendell \
|
||||
--dns-provider="google-clouddns" \
|
||||
--dns-zone-name="example.com." \
|
||||
--api-server-service-type="NodePort" \
|
||||
--api-server-advertise-address="10.0.10.20"
|
||||
```
|
||||
|
||||
#### Provisioning storage for etcd
|
||||
|
||||
Federation control plane stores its state in
|
||||
[`etcd`](https://coreos.com/etcd/docs/latest/).
|
||||
[`etcd`](https://coreos.com/etcd/docs/latest/) data must be stored in
|
||||
a persistent storage volume to ensure correct operation across
|
||||
federation control plane restarts. On host clusters that support
|
||||
[dynamic provisioning of storage volumes](/docs/concepts/storage/persistent-volumes/#dynamic),
|
||||
`kubefed init` dynamically provisions a
|
||||
[`PersistentVolume`](/docs/concepts/storage/persistent-volumes/#persistent-volumes)
|
||||
and binds it to a
|
||||
[`PersistentVolumeClaim`](/docs/concepts/storage/persistent-volumes/#persistentvolumeclaims)
|
||||
to store [`etcd`](https://coreos.com/etcd/docs/latest/) data. If your
|
||||
host cluster doesn't support dynamic provisioning, you can also
|
||||
statically provision a
|
||||
[`PersistentVolume`](/docs/concepts/storage/persistent-volumes/#persistent-volumes).
|
||||
`kubefed init` creates a
|
||||
[`PersistentVolumeClaim`](/docs/concepts/storage/persistent-volumes/#persistentvolumeclaims)
|
||||
that has the following configuration:
|
||||
|
||||
```yaml
|
||||
apiVersion: v1
|
||||
kind: PersistentVolumeClaim
|
||||
metadata:
|
||||
annotations:
|
||||
volume.alpha.kubernetes.io/storage-class: "yes"
|
||||
labels:
|
||||
app: federated-cluster
|
||||
name: fellowship-federation-apiserver-etcd-claim
|
||||
namespace: federation-system
|
||||
spec:
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
resources:
|
||||
requests:
|
||||
storage: 10Gi
|
||||
```
|
||||
|
||||
To statically provision a
|
||||
[`PersistentVolume`](/docs/concepts/storage/persistent-volumes/#persistent-volumes),
|
||||
you must ensure that the
|
||||
[`PersistentVolume`](/docs/concepts/storage/persistent-volumes/#persistent-volumes)
|
||||
that you create has the matching storage class, access mode and
|
||||
at least as much capacity as the requested
|
||||
[`PersistentVolumeClaim`](/docs/concepts/storage/persistent-volumes/#persistentvolumeclaims).
|
||||
|
||||
Alternatively, you can disable persistent storage completely
|
||||
by passing `--etcd-persistent-storage=false` to `kubefed init`.
|
||||
However, we do not recommended this because your federation control
|
||||
plane cannot survive restarts in this mode.
|
||||
|
||||
```shell
|
||||
kubefed init fellowship \
|
||||
--host-cluster-context=rivendell \
|
||||
--dns-provider="google-clouddns" \
|
||||
--dns-zone-name="example.com." \
|
||||
--etcd-persistent-storage=false
|
||||
```
|
||||
|
||||
`kubefed init` still doesn't support attaching an existing
|
||||
[`PersistentVolumeClaim`](/docs/concepts/storage/persistent-volumes/#persistentvolumeclaims)
|
||||
to the federation control plane that it bootstraps. We are planning to
|
||||
support this in a future version of `kubefed`.
|
||||
|
||||
#### CoreDNS support
|
||||
|
||||
Federated services now support [CoreDNS](https://coredns.io/) as one
|
||||
of the DNS providers. If you are running your clusters and federation
|
||||
in an environment that does not have access to cloud-based DNS
|
||||
providers, then you can run your own [CoreDNS](https://coredns.io/)
|
||||
instance and publish the federated service DNS names to that server.
|
||||
|
||||
You can configure your federation to use
|
||||
[CoreDNS](https://coredns.io/), by passing appropriate values to
|
||||
`kubefed init`'s `--dns-provider` and `--dns-provider-config` flags.
|
||||
|
||||
```shell
|
||||
kubefed init fellowship \
|
||||
--host-cluster-context=rivendell \
|
||||
--dns-provider="coredns" \
|
||||
--dns-zone-name="example.com." \
|
||||
--dns-provider-config="$HOME/coredns-provider.conf"
|
||||
```
|
||||
|
||||
For more information see
|
||||
[Setting up CoreDNS as DNS provider for Cluster Federation](/docs/tasks/federation/set-up-coredns-provider-federation/).
|
||||
|
||||
#### AWS Route53 support
|
||||
|
||||
It is possible to utilize AWS Route53 as a cloud DNS provider when the
|
||||
federation controller-manager is run on-premise. The controller-manager
|
||||
Deployment must be configured with AWS credentials since it cannot implicity
|
||||
gather them from a VM running on AWS.
|
||||
|
||||
Currently, `kubefed init` does not read AWS Route53 credentials from the
|
||||
`--dns-provider-config` flag, so a patch must be applied.
|
||||
|
||||
Specify AWS Route53 as your DNS provider when initializing your on-premise
|
||||
federation controller-manager by passing the flag `--dns-provider="aws-route53"`
|
||||
to `kubefed init`.
|
||||
|
||||
Create a patch file with your AWS credentials:
|
||||
|
||||
```yaml
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- name: controller-manager
|
||||
env:
|
||||
- name: AWS_ACCESS_KEY_ID
|
||||
value: "ABCDEFG1234567890"
|
||||
- name: AWS_SECRET_ACCESS_KEY
|
||||
value: "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
|
||||
```
|
||||
|
||||
Patch the Deployment:
|
||||
|
||||
```shell
|
||||
kubectl -n federation-system patch deployment controller-manager --patch "$(cat <patch-file-name>.yml)"
|
||||
```
|
||||
|
||||
Where `<patch-file-name>` is the name of the file you created above.
|
||||
|
||||
## Adding a cluster to a federation
|
||||
|
||||
After you've deployed a federation control plane, you'll need to make that control plane aware of the clusters it should manage.
|
||||
|
||||
To join clusters into the federation:
|
||||
|
||||
1. Change the context:
|
||||
|
||||
kubectl config use-context fellowship
|
||||
|
||||
1. If you are using a managed cluster service, allow the service to access the cluster. To do this, create a `clusterrolebinding` for the account associated with your cluster service:
|
||||
|
||||
kubectl create clusterrolebinding <your_user>-cluster-admin-binding --clusterrole=cluster-admin --user=<your_user>@example.org --context=<joining_cluster_context>
|
||||
|
||||
1. Join the cluster to the federation, using `kubefed join`, and make sure you provide the following:
|
||||
|
||||
* The name of the cluster that you are joining to the federation
|
||||
* `--host-cluster-context`, the kubeconfig context for the host cluster
|
||||
|
||||
For example, this command adds the cluster `gondor` to the federation running on host cluster `rivendell`:
|
||||
|
||||
```
|
||||
kubefed join gondor --host-cluster-context=rivendell
|
||||
```
|
||||
|
||||
A new context has now been added to your kubeconfig named `fellowship` (after the name of your federation).
|
||||
|
||||
|
||||
> Note: The name that you provide to the `join` command is used as the joining cluster's identity in federation. If this name adheres to the rules described in the [identifiers doc](/docs/concepts/overview/working-with-objects/names/). If the context
|
||||
corresponding to your joining cluster conforms to these rules then you can use the same name in the join command. Otherwise, you will have to choose a different name for your cluster's identity.
|
||||
|
||||
|
||||
### Naming rules and customization
|
||||
|
||||
The cluster name you supply to `kubefed join` must be a valid
|
||||
[RFC 1035](https://www.ietf.org/rfc/rfc1035.txt) label and are
|
||||
enumerated in the [Identifiers doc](/docs/concepts/overview/working-with-objects/names/).
|
||||
|
||||
Furthermore, federation control plane requires credentials of the
|
||||
joined clusters to operate on them. These credentials are obtained
|
||||
from the local kubeconfig. `kubefed join` uses the cluster name
|
||||
specified as the argument to look for the cluster's context in the
|
||||
local kubeconfig. If it fails to find a matching context, it exits
|
||||
with an error.
|
||||
|
||||
This might cause issues in cases where context names for each cluster
|
||||
in the federation don't follow
|
||||
[RFC 1035](https://www.ietf.org/rfc/rfc1035.txt) label naming rules.
|
||||
In such cases, you can specify a cluster name that conforms to the
|
||||
[RFC 1035](https://www.ietf.org/rfc/rfc1035.txt) label naming rules
|
||||
and specify the cluster context using the `--cluster-context` flag.
|
||||
For example, if context of the cluster you are joining is
|
||||
`gondor_needs-no_king`, then you can join the cluster by running:
|
||||
|
||||
```shell
|
||||
kubefed join gondor --host-cluster-context=rivendell --cluster-context=gondor_needs-no_king
|
||||
```
|
||||
|
||||
#### Secret name
|
||||
|
||||
Cluster credentials required by the federation control plane as
|
||||
described above are stored as a secret in the host cluster. The name
|
||||
of the secret is also derived from the cluster name.
|
||||
|
||||
However, the name of a secret object in Kubernetes should conform
|
||||
to the DNS subdomain name specification described in
|
||||
[RFC 1123](https://tools.ietf.org/html/rfc1123). If this isn't the
|
||||
case, you can pass the secret name to `kubefed join` using the
|
||||
`--secret-name` flag. For example, if the cluster name is `noldor` and
|
||||
the secret name is `11kingdom`, you can join the cluster by
|
||||
running:
|
||||
|
||||
```shell
|
||||
kubefed join noldor --host-cluster-context=rivendell --secret-name=11kingdom
|
||||
```
|
||||
|
||||
Note: If your cluster name does not conform to the DNS subdomain name
|
||||
specification, all you need to do is supply the secret name via the
|
||||
`--secret-name` flag. `kubefed join` automatically creates the secret
|
||||
for you.
|
||||
|
||||
### `kube-dns` configuration
|
||||
|
||||
`kube-dns` configuration must be updated in each joining cluster to
|
||||
enable federated service discovery. If the joining Kubernetes cluster
|
||||
is version 1.5 or newer and your `kubefed` is version 1.6 or newer,
|
||||
then this configuration is automatically managed for you when the
|
||||
clusters are joined or unjoined using `kubefed join` or `unjoin`
|
||||
commands.
|
||||
|
||||
In all other cases, you must update `kube-dns` configuration manually
|
||||
as described in the
|
||||
[Updating KubeDNS section of the admin guide](/docs/admin/federation/).
|
||||
|
||||
## Removing a cluster from a federation
|
||||
|
||||
To remove a cluster from a federation, run the [`kubefed unjoin`](/docs/admin/kubefed_unjoin/)
|
||||
command with the cluster name and the federation's
|
||||
`--host-cluster-context`:
|
||||
|
||||
```
|
||||
kubefed unjoin gondor --host-cluster-context=rivendell
|
||||
```
|
||||
|
||||
## Turning down the federation control plane
|
||||
|
||||
Proper cleanup of federation control plane is not fully implemented in
|
||||
this beta release of `kubefed`. However, for the time being, deleting
|
||||
the federation system namespace should remove all the resources except
|
||||
the persistent storage volume dynamically provisioned for the
|
||||
federation control plane's etcd. You can delete the federation
|
||||
namespace by running the following command:
|
||||
|
||||
```
|
||||
kubectl delete ns federation-system --context=rivendell
|
||||
```
|
||||
|
||||
Note that `rivendell` is the host cluster name, replace that with the
|
||||
appropriate name in your configuration.
|
||||
@@ -0,0 +1,135 @@
|
||||
---
|
||||
title: Set up CoreDNS as DNS provider for Cluster Federation
|
||||
content_template: templates/tutorial
|
||||
---
|
||||
|
||||
{{% capture overview %}}
|
||||
|
||||
{{< include "federation-current-state.md" >}}
|
||||
|
||||
This page shows how to configure and deploy CoreDNS to be used as the
|
||||
DNS provider for Cluster Federation.
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
|
||||
{{% capture objectives %}}
|
||||
|
||||
* Configure and deploy CoreDNS server
|
||||
* Bring up federation with CoreDNS as dns provider
|
||||
* Setup CoreDNS server in nameserver lookup chain
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
|
||||
{{% capture prerequisites %}}
|
||||
|
||||
* You need to have a running Kubernetes cluster (which is
|
||||
referenced as host cluster). Please see one of the
|
||||
[getting started](/docs/setup/) guides for
|
||||
installation instructions for your platform.
|
||||
* Support for `LoadBalancer` services in member clusters of federation is
|
||||
mandatory to enable `CoreDNS` for service discovery across federated clusters.
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
|
||||
{{% capture lessoncontent %}}
|
||||
|
||||
## Deploying CoreDNS and etcd charts
|
||||
|
||||
CoreDNS can be deployed in various configurations. Explained below is a
|
||||
reference and can be tweaked to suit the needs of the platform and the
|
||||
cluster federation.
|
||||
|
||||
To deploy CoreDNS, we shall make use of helm charts. CoreDNS will be
|
||||
deployed with [etcd](https://coreos.com/etcd) as the backend and should
|
||||
be pre-installed. etcd can also be deployed using helm charts. Shown
|
||||
below are the instructions to deploy etcd.
|
||||
|
||||
helm install --namespace my-namespace --name etcd-operator stable/etcd-operator
|
||||
helm upgrade --namespace my-namespace --set cluster.enabled=true etcd-operator stable/etcd-operator
|
||||
|
||||
*Note: etcd default deployment configurations can be overridden, suiting the
|
||||
host cluster.*
|
||||
|
||||
After deployment succeeds, etcd can be accessed with the
|
||||
[http://etcd-cluster.my-namespace:2379](http://etcd-cluster.my-namespace:2379) endpoint within the host cluster.
|
||||
|
||||
The CoreDNS default configuration should be customized to suit the federation.
|
||||
Shown below is the Values.yaml, which overrides the default
|
||||
configuration parameters on the CoreDNS chart.
|
||||
|
||||
{{< code file="Values.yaml" >}}
|
||||
|
||||
The above configuration file needs some explanation:
|
||||
|
||||
- `isClusterService` specifies whether CoreDNS should be deployed as a
|
||||
cluster-service, which is the default. You need to set it to false, so
|
||||
that CoreDNS is deployed as a Kubernetes application service.
|
||||
- `serviceType` specifies the type of Kubernetes service to be created
|
||||
for CoreDNS. You need to choose either "LoadBalancer" or "NodePort" to
|
||||
make the CoreDNS service accessible outside the Kubernetes cluster.
|
||||
- Disable `middleware.kubernetes`, which is enabled by default by
|
||||
setting `middleware.kubernetes.enabled` to false.
|
||||
- Enable `middleware.etcd` by setting `middleware.etcd.enabled` to
|
||||
true.
|
||||
- Configure the DNS zone (federation domain) for which CoreDNS is
|
||||
authoritative by setting `middleware.etcd.zones` as shown above.
|
||||
- Configure the etcd endpoint which was deployed earlier by setting
|
||||
`middleware.etcd.endpoint`
|
||||
|
||||
Now deploy CoreDNS by running
|
||||
|
||||
helm install --namespace my-namespace --name coredns -f Values.yaml stable/coredns
|
||||
|
||||
Verify that both etcd and CoreDNS pods are running as expected.
|
||||
|
||||
|
||||
## Deploying Federation with CoreDNS as DNS provider
|
||||
|
||||
The Federation control plane can be deployed using `kubefed init`. CoreDNS
|
||||
can be chosen as the DNS provider by specifying two additional parameters.
|
||||
|
||||
--dns-provider=coredns
|
||||
--dns-provider-config=coredns-provider.conf
|
||||
|
||||
coredns-provider.conf has below format:
|
||||
|
||||
[Global]
|
||||
etcd-endpoints = http://etcd-cluster.my-namespace:2379
|
||||
zones = example.com.
|
||||
coredns-endpoints = <coredns-server-ip>:<port>
|
||||
|
||||
- `etcd-endpoints` is the endpoint to access etcd.
|
||||
- `zones` is the federation domain for which CoreDNS is authoritative and is same as --dns-zone-name flag of `kubefed init`.
|
||||
- `coredns-endpoints` is the endpoint to access CoreDNS server. This is an optional parameter introduced from v1.7 onwards.
|
||||
|
||||
*Note: middleware.etcd.zones in CoreDNS configuration and --dns-zone-name
|
||||
flag to kubefed init should match.*
|
||||
|
||||
|
||||
## Setup CoreDNS server in nameserver resolv.conf chain
|
||||
|
||||
*Note: The following section applies only to versions prior to v1.7
|
||||
and will be automatically taken care of if the `coredns-endpoints`
|
||||
parameter is configured in `coredns-provider.conf` as described in
|
||||
section above.*
|
||||
|
||||
Once the federation control plane is deployed and federated clusters
|
||||
are joined to the federation, you need to add the CoreDNS server to the
|
||||
pod's nameserver resolv.conf chain in all the federated clusters as this
|
||||
self hosted CoreDNS server is not discoverable publicly. This can be
|
||||
achieved by adding the below line to `dnsmasq` container's arg in
|
||||
`kube-dns` deployment.
|
||||
|
||||
--server=/example.com./<CoreDNS endpoint>
|
||||
|
||||
Replace `example.com` above with federation domain.
|
||||
|
||||
|
||||
Now the federated cluster is ready for cross-cluster service discovery!
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
|
||||
@@ -0,0 +1,143 @@
|
||||
---
|
||||
title: Set up placement policies in Federation
|
||||
content_template: templates/task
|
||||
---
|
||||
|
||||
{{% capture overview %}}
|
||||
|
||||
{{< include "federation-current-state.md" >}}
|
||||
|
||||
This page shows how to enforce policy-based placement decisions over Federated
|
||||
resources using an external policy engine.
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
{{% capture prerequisites %}}
|
||||
|
||||
You need to have a running Kubernetes cluster (which is referenced as host
|
||||
cluster). Please see one of the [getting started](/docs/setup/)
|
||||
guides for installation instructions for your platform.
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
{{% capture steps %}}
|
||||
|
||||
## Deploying Federation and configuring an external policy engine
|
||||
|
||||
The Federation control plane can be deployed using `kubefed init`.
|
||||
|
||||
After deploying the Federation control plane, you must configure an Admission
|
||||
Controller in the Federation API server that enforces placement decisions
|
||||
received from the external policy engine.
|
||||
|
||||
kubectl create -f scheduling-policy-admission.yaml
|
||||
|
||||
Shown below is an example ConfigMap for the Admission Controller:
|
||||
|
||||
{{< code file="scheduling-policy-admission.yaml" >}}
|
||||
|
||||
The ConfigMap contains three files:
|
||||
|
||||
* `config.yml` specifies the location of the `SchedulingPolicy` Admission
|
||||
Controller config file.
|
||||
* `scheduling-policy-config.yml` specifies the location of the kubeconfig file
|
||||
required to contact the external policy engine. This file can also include a
|
||||
`retryBackoff` value that controls the initial retry backoff delay in
|
||||
milliseconds.
|
||||
* `opa-kubeconfig` is a standard kubeconfig containing the URL and credentials
|
||||
needed to contact the external policy engine.
|
||||
|
||||
Edit the Federation API server deployment to enable the `SchedulingPolicy`
|
||||
Admission Controller.
|
||||
|
||||
kubectl -n federation-system edit deployment federation-apiserver
|
||||
|
||||
Update the Federation API server command line arguments to enable the Admission
|
||||
Controller and mount the ConfigMap into the container. If there's an existing
|
||||
`--enable-admission-plugins` flag, append `,SchedulingPolicy` instead of adding
|
||||
another line.
|
||||
|
||||
--enable-admission-plugins=SchedulingPolicy
|
||||
--admission-control-config-file=/etc/kubernetes/admission/config.yml
|
||||
|
||||
Add the following volume to the Federation API server pod:
|
||||
|
||||
- name: admission-config
|
||||
configMap:
|
||||
name: admission
|
||||
|
||||
Add the following volume mount the Federation API server `apiserver` container:
|
||||
|
||||
volumeMounts:
|
||||
- name: admission-config
|
||||
mountPath: /etc/kubernetes/admission
|
||||
|
||||
## Deploying an external policy engine
|
||||
|
||||
The [Open Policy Agent (OPA)](http://openpolicyagent.org) is an open source,
|
||||
general-purpose policy engine that you can use to enforce policy-based placement
|
||||
decisions in the Federation control plane.
|
||||
|
||||
Create a Service in the host cluster to contact the external policy engine:
|
||||
|
||||
kubectl create -f policy-engine-service.yaml
|
||||
|
||||
Shown below is an example Service for OPA.
|
||||
|
||||
{{< code file="policy-engine-service.yaml" >}}
|
||||
|
||||
Create a Deployment in the host cluster with the Federation control plane:
|
||||
|
||||
kubectl create -f policy-engine-deployment.yaml
|
||||
|
||||
Shown below is an example Deployment for OPA.
|
||||
|
||||
{{< code file="policy-engine-deployment.yaml" >}}
|
||||
|
||||
## Configuring placement policies via ConfigMaps
|
||||
|
||||
The external policy engine will discover placement policies created in the
|
||||
`kube-federation-scheduling-policy` namespace in the Federation API server.
|
||||
|
||||
Create the namespace if it does not already exist:
|
||||
|
||||
kubectl --context=federation create namespace kube-federation-scheduling-policy
|
||||
|
||||
Configure a sample policy to test the external policy engine:
|
||||
|
||||
{{< code file="policy.rego" >}}
|
||||
|
||||
Shown below is the command to create the sample policy:
|
||||
|
||||
kubectl --context=federation -n kube-federation-scheduling-policy create configmap scheduling-policy --from-file=policy.rego
|
||||
|
||||
This sample policy illustrates a few key ideas:
|
||||
|
||||
* Placement policies can refer to any field in Federated resources.
|
||||
* Placement policies can leverage external context (for example, Cluster
|
||||
metadata) to make decisions.
|
||||
* Administrative policy can be managed centrally.
|
||||
* Policies can define simple interfaces (such as the `requires-pci` annotation) to
|
||||
avoid duplicating logic in manifests.
|
||||
|
||||
## Testing placement policies
|
||||
|
||||
Annotate one of the clusters to indicate that it is PCI certified.
|
||||
|
||||
kubectl --context=federation annotate clusters cluster-name-1 pci-certified=true
|
||||
|
||||
Deploy a Federated ReplicaSet to test the placement policy.
|
||||
|
||||
{{< code file="replicaset-example-policy.yaml" >}}
|
||||
|
||||
Shown below is the command to deploy a ReplicaSet that *does* match the policy.
|
||||
|
||||
kubectl --context=federation create -f replicaset-example-policy.yaml
|
||||
|
||||
Inspect the ReplicaSet to confirm the appropriate annotations have been applied:
|
||||
|
||||
kubectl --context=federation get rs nginx-pci -o jsonpath='{.metadata.annotations}'
|
||||
|
||||
{{% /capture %}}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user