Providing Feedback

Provide feedback at the survey

TL;DR
  • Target a cluster for a rollout with the --context flag
  • Target a cluster for a rollout with the --kubeconfig flag

Multi-Cluster Targeting

Motivation

It is common for users to need to deploy different Variants of an Application to different clusters. This can be done by configuring the different Variants using different kustomization.yaml's, and targeting each variant using the --context or --kubeconfig flag.

Note: The examples shown in this chapter store the Resource Config in a directory matching the name of the cluster (i.e. as it is referred to be context).

Targeting a Cluster via Context

The kubeconfig file allows multiple contexts to be specified, each with a different cluster + auth.

List Contexts

List the contexts in the kubeconfig file

kubectl config get-contexts
CURRENT   NAME   CLUSTER   AUTHINFO   NAMESPACE
          us-central1-c  us-central1-c  us-central1-c
*         us-east1-c  us-east1-c  us-east1-c
          us-west2-c   us-west2-c   us-west2-c

Print information about the current context

kubectl config --kubeconfig=config-demo view --minify
apiVersion: v1
clusters:
- cluster:
    certificate-authority: fake-ca-file
    server: https://1.2.3.4
  name: development
contexts:
- context:
    cluster: development
    namespace: frontend
    user: developer
  name: dev-frontend
current-context: dev-frontend
kind: Config
preferences: {}
users:
- name: developer
  user:
    client-certificate: fake-cert-file
    client-key: fake-key-file

Specify a Context Flag

Specify the kubeconfig context as part of the command.

Note: In this example the kustomization.yaml exists in a directory whose name matches the name of the context.

export CLUSTER=us-west2-c; kubectl apply -k ${CLUSTER} --context=${CLUSTER}

Switch to use a Context

Switch the current context before running the command.

Note: In this example the kustomization.yaml exists in a directory whose name matches the name of the context.

# change the context to us-west2-c
kubectl config use-context us-west2-c
# deploy Resources from the ./us-west2-c/kustomization.yaml
kubectl apply -k ./us-west2-c

Targeting a Cluster via Kubeconfig

Alternatively, different kubeconfig files may be used for different clusters. The kubeconfig may be specified with the --kubeconfig flag.

Note: In this example the kustomization.yaml exists in a directory whose name matches the name of the directory containing the kubeconfig.

kubectl apply -k ./us-west2-c --kubeconfig /path/to/us-west2-c/config

More Info

For more information on configuring kubeconfig and contexts, see the Configure Access to Multiple Clusters k8s.io document.

results matching ""

    No results matching ""