sigs.k8s.io/cluster-api/bootstrap/kubeadm@v0.0.0-20191016155141-23a891785b60/kubeadm/v1beta1/types.go (about)

     1  /*
     2  Copyright 2018 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package v1beta1
    18  
    19  import (
    20  	v1 "k8s.io/api/core/v1"
    21  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    22  )
    23  
    24  // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
    25  
    26  // InitConfiguration contains a list of elements that is specific "kubeadm init"-only runtime
    27  // information.
    28  type InitConfiguration struct {
    29  	metav1.TypeMeta `json:",inline"`
    30  
    31  	// ClusterConfiguration holds the cluster-wide information, and embeds that struct (which can be (un)marshalled separately as well)
    32  	// When InitConfiguration is marshalled to bytes in the external version, this information IS NOT preserved (which can be seen from
    33  	// the `json:"-"` tag. This is due to that when InitConfiguration is (un)marshalled, it turns into two YAML documents, one for the
    34  	// InitConfiguration and ClusterConfiguration. Hence, the information must not be duplicated, and is therefore omitted here.
    35  	ClusterConfiguration `json:"-"`
    36  
    37  	// `kubeadm init`-only information. These fields are solely used the first time `kubeadm init` runs.
    38  	// After that, the information in the fields IS NOT uploaded to the `kubeadm-config` ConfigMap
    39  	// that is used by `kubeadm upgrade` for instance. These fields must be omitempty.
    40  
    41  	// BootstrapTokens is respected at `kubeadm init` time and describes a set of Bootstrap Tokens to create.
    42  	// This information IS NOT uploaded to the kubeadm cluster configmap, partly because of its sensitive nature
    43  	BootstrapTokens []BootstrapToken `json:"bootstrapTokens,omitempty"`
    44  
    45  	// NodeRegistration holds fields that relate to registering the new control-plane node to the cluster
    46  	NodeRegistration NodeRegistrationOptions `json:"nodeRegistration,omitempty"`
    47  
    48  	// LocalAPIEndpoint represents the endpoint of the API server instance that's deployed on this control plane node
    49  	// In HA setups, this differs from ClusterConfiguration.ControlPlaneEndpoint in the sense that ControlPlaneEndpoint
    50  	// is the global endpoint for the cluster, which then loadbalances the requests to each individual API server. This
    51  	// configuration object lets you customize what IP/DNS name and port the local API server advertises it's accessible
    52  	// on. By default, kubeadm tries to auto-detect the IP of the default interface and use that, but in case that process
    53  	// fails you may set the desired value here.
    54  	LocalAPIEndpoint APIEndpoint `json:"localAPIEndpoint,omitempty"`
    55  }
    56  
    57  // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
    58  
    59  // ClusterConfiguration contains cluster-wide configuration for a kubeadm cluster
    60  type ClusterConfiguration struct {
    61  	metav1.TypeMeta `json:",inline"`
    62  
    63  	// Etcd holds configuration for etcd.
    64  	// +optional
    65  	Etcd Etcd `json:"etcd"`
    66  
    67  	// Networking holds configuration for the networking topology of the cluster.
    68  	// NB: This value defaults to the Cluster object spec.clusterNetwork.
    69  	// +optional
    70  	Networking Networking `json:"networking"`
    71  
    72  	// KubernetesVersion is the target version of the control plane.
    73  	// NB: This value defaults to the Machine object spec.kuberentesVersion
    74  	// +optional
    75  	KubernetesVersion string `json:"kubernetesVersion"`
    76  
    77  	// ControlPlaneEndpoint sets a stable IP address or DNS name for the control plane; it
    78  	// can be a valid IP address or a RFC-1123 DNS subdomain, both with optional TCP port.
    79  	// In case the ControlPlaneEndpoint is not specified, the AdvertiseAddress + BindPort
    80  	// are used; in case the ControlPlaneEndpoint is specified but without a TCP port,
    81  	// the BindPort is used.
    82  	// Possible usages are:
    83  	// e.g. In a cluster with more than one control plane instances, this field should be
    84  	// assigned the address of the external load balancer in front of the
    85  	// control plane instances.
    86  	// e.g.  in environments with enforced node recycling, the ControlPlaneEndpoint
    87  	// could be used for assigning a stable DNS to the control plane.
    88  	// NB: This value defaults to the first value in the Cluster object status.apiEndpoints array.
    89  	// +optional
    90  	ControlPlaneEndpoint string `json:"controlPlaneEndpoint"`
    91  
    92  	// APIServer contains extra settings for the API server control plane component
    93  	APIServer APIServer `json:"apiServer,omitempty"`
    94  
    95  	// ControllerManager contains extra settings for the controller manager control plane component
    96  	ControllerManager ControlPlaneComponent `json:"controllerManager,omitempty"`
    97  
    98  	// Scheduler contains extra settings for the scheduler control plane component
    99  	Scheduler ControlPlaneComponent `json:"scheduler,omitempty"`
   100  
   101  	// DNS defines the options for the DNS add-on installed in the cluster.
   102  	// +optional
   103  	DNS DNS `json:"dns"`
   104  
   105  	// CertificatesDir specifies where to store or look for all required certificates.
   106  	// +optional
   107  	CertificatesDir string `json:"certificatesDir"`
   108  
   109  	// ImageRepository sets the container registry to pull images from.
   110  	// If empty, `k8s.gcr.io` will be used by default; in case of kubernetes version is a CI build (kubernetes version starts with `ci/` or `ci-cross/`)
   111  	// `gcr.io/kubernetes-ci-images` will be used as a default for control plane components and for kube-proxy, while `k8s.gcr.io`
   112  	// will be used for all the other images.
   113  	// +optional
   114  	ImageRepository string `json:"imageRepository"`
   115  
   116  	// UseHyperKubeImage controls if hyperkube should be used for Kubernetes components instead of their respective separate images
   117  	UseHyperKubeImage bool `json:"useHyperKubeImage,omitempty"`
   118  
   119  	// FeatureGates enabled by the user.
   120  	FeatureGates map[string]bool `json:"featureGates,omitempty"`
   121  
   122  	// The cluster name
   123  	// +optional
   124  	ClusterName string `json:"clusterName,omitempty"`
   125  }
   126  
   127  // ControlPlaneComponent holds settings common to control plane component of the cluster
   128  type ControlPlaneComponent struct {
   129  	// ExtraArgs is an extra set of flags to pass to the control plane component.
   130  	// TODO: This is temporary and ideally we would like to switch all components to
   131  	// use ComponentConfig + ConfigMaps.
   132  	ExtraArgs map[string]string `json:"extraArgs,omitempty"`
   133  
   134  	// ExtraVolumes is an extra set of host volumes, mounted to the control plane component.
   135  	ExtraVolumes []HostPathMount `json:"extraVolumes,omitempty"`
   136  }
   137  
   138  // APIServer holds settings necessary for API server deployments in the cluster
   139  type APIServer struct {
   140  	ControlPlaneComponent `json:",inline"`
   141  
   142  	// CertSANs sets extra Subject Alternative Names for the API Server signing cert.
   143  	CertSANs []string `json:"certSANs,omitempty"`
   144  
   145  	// TimeoutForControlPlane controls the timeout that we use for API server to appear
   146  	TimeoutForControlPlane *metav1.Duration `json:"timeoutForControlPlane,omitempty"`
   147  }
   148  
   149  // DNSAddOnType defines string identifying DNS add-on types
   150  type DNSAddOnType string
   151  
   152  const (
   153  	// CoreDNS add-on type
   154  	CoreDNS DNSAddOnType = "CoreDNS"
   155  
   156  	// KubeDNS add-on type
   157  	KubeDNS DNSAddOnType = "kube-dns"
   158  )
   159  
   160  // DNS defines the DNS addon that should be used in the cluster
   161  type DNS struct {
   162  	// Type defines the DNS add-on to be used
   163  	Type DNSAddOnType `json:"type"`
   164  
   165  	// ImageMeta allows to customize the image used for the DNS component
   166  	ImageMeta `json:",inline"`
   167  }
   168  
   169  // ImageMeta allows to customize the image used for components that are not
   170  // originated from the Kubernetes/Kubernetes release process
   171  type ImageMeta struct {
   172  	// ImageRepository sets the container registry to pull images from.
   173  	// if not set, the ImageRepository defined in ClusterConfiguration will be used instead.
   174  	ImageRepository string `json:"imageRepository,omitempty"`
   175  
   176  	// ImageTag allows to specify a tag for the image.
   177  	// In case this value is set, kubeadm does not change automatically the version of the above components during upgrades.
   178  	ImageTag string `json:"imageTag,omitempty"`
   179  
   180  	//TODO: evaluate if we need also a ImageName based on user feedbacks
   181  }
   182  
   183  // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
   184  
   185  // ClusterStatus contains the cluster status. The ClusterStatus will be stored in the kubeadm-config
   186  // ConfigMap in the cluster, and then updated by kubeadm when additional control plane instance joins or leaves the cluster.
   187  type ClusterStatus struct {
   188  	metav1.TypeMeta `json:",inline"`
   189  
   190  	// APIEndpoints currently available in the cluster, one for each control plane/api server instance.
   191  	// The key of the map is the IP of the host's default interface
   192  	APIEndpoints map[string]APIEndpoint `json:"apiEndpoints"`
   193  }
   194  
   195  // APIEndpoint struct contains elements of API server instance deployed on a node.
   196  type APIEndpoint struct {
   197  	// AdvertiseAddress sets the IP address for the API server to advertise.
   198  	AdvertiseAddress string `json:"advertiseAddress"`
   199  
   200  	// BindPort sets the secure port for the API Server to bind to.
   201  	// Defaults to 6443.
   202  	BindPort int32 `json:"bindPort"`
   203  }
   204  
   205  // NodeRegistrationOptions holds fields that relate to registering a new control-plane or node to the cluster, either via "kubeadm init" or "kubeadm join"
   206  type NodeRegistrationOptions struct {
   207  
   208  	// Name is the `.Metadata.Name` field of the Node API object that will be created in this `kubeadm init` or `kubeadm join` operation.
   209  	// This field is also used in the CommonName field of the kubelet's client certificate to the API server.
   210  	// Defaults to the hostname of the node if not provided.
   211  	Name string `json:"name,omitempty"`
   212  
   213  	// CRISocket is used to retrieve container runtime info. This information will be annotated to the Node API object, for later re-use
   214  	CRISocket string `json:"criSocket,omitempty"`
   215  
   216  	// Taints specifies the taints the Node API object should be registered with. If this field is unset, i.e. nil, in the `kubeadm init` process
   217  	// it will be defaulted to []v1.Taint{'node-role.kubernetes.io/master=""'}. If you don't want to taint your control-plane node, set this field to an
   218  	// empty slice, i.e. `taints: {}` in the YAML file. This field is solely used for Node registration.
   219  	Taints []v1.Taint `json:"taints,omitempty"`
   220  
   221  	// KubeletExtraArgs passes through extra arguments to the kubelet. The arguments here are passed to the kubelet command line via the environment file
   222  	// kubeadm writes at runtime for the kubelet to source. This overrides the generic base-level configuration in the kubelet-config-1.X ConfigMap
   223  	// Flags have higher priority when parsing. These values are local and specific to the node kubeadm is executing on.
   224  	KubeletExtraArgs map[string]string `json:"kubeletExtraArgs,omitempty"`
   225  }
   226  
   227  // Networking contains elements describing cluster's networking configuration
   228  type Networking struct {
   229  	// ServiceSubnet is the subnet used by k8s services. Defaults to "10.96.0.0/12".
   230  	ServiceSubnet string `json:"serviceSubnet"`
   231  	// PodSubnet is the subnet used by pods.
   232  	PodSubnet string `json:"podSubnet"`
   233  	// DNSDomain is the dns domain used by k8s services. Defaults to "cluster.local".
   234  	DNSDomain string `json:"dnsDomain"`
   235  }
   236  
   237  // BootstrapToken describes one bootstrap token, stored as a Secret in the cluster
   238  type BootstrapToken struct {
   239  	// Token is used for establishing bidirectional trust between nodes and control-planes.
   240  	// Used for joining nodes in the cluster.
   241  	Token *BootstrapTokenString `json:"token"`
   242  	// Description sets a human-friendly message why this token exists and what it's used
   243  	// for, so other administrators can know its purpose.
   244  	Description string `json:"description,omitempty"`
   245  	// TTL defines the time to live for this token. Defaults to 24h.
   246  	// Expires and TTL are mutually exclusive.
   247  	TTL *metav1.Duration `json:"ttl,omitempty"`
   248  	// Expires specifies the timestamp when this token expires. Defaults to being set
   249  	// dynamically at runtime based on the TTL. Expires and TTL are mutually exclusive.
   250  	Expires *metav1.Time `json:"expires,omitempty"`
   251  	// Usages describes the ways in which this token can be used. Can by default be used
   252  	// for establishing bidirectional trust, but that can be changed here.
   253  	Usages []string `json:"usages,omitempty"`
   254  	// Groups specifies the extra groups that this token will authenticate as when/if
   255  	// used for authentication
   256  	Groups []string `json:"groups,omitempty"`
   257  }
   258  
   259  // Etcd contains elements describing Etcd configuration.
   260  type Etcd struct {
   261  
   262  	// Local provides configuration knobs for configuring the local etcd instance
   263  	// Local and External are mutually exclusive
   264  	Local *LocalEtcd `json:"local,omitempty"`
   265  
   266  	// External describes how to connect to an external etcd cluster
   267  	// Local and External are mutually exclusive
   268  	External *ExternalEtcd `json:"external,omitempty"`
   269  }
   270  
   271  // LocalEtcd describes that kubeadm should run an etcd cluster locally
   272  type LocalEtcd struct {
   273  	// ImageMeta allows to customize the container used for etcd
   274  	ImageMeta `json:",inline"`
   275  
   276  	// DataDir is the directory etcd will place its data.
   277  	// Defaults to "/var/lib/etcd".
   278  	DataDir string `json:"dataDir"`
   279  
   280  	// ExtraArgs are extra arguments provided to the etcd binary
   281  	// when run inside a static pod.
   282  	ExtraArgs map[string]string `json:"extraArgs,omitempty"`
   283  
   284  	// ServerCertSANs sets extra Subject Alternative Names for the etcd server signing cert.
   285  	ServerCertSANs []string `json:"serverCertSANs,omitempty"`
   286  	// PeerCertSANs sets extra Subject Alternative Names for the etcd peer signing cert.
   287  	PeerCertSANs []string `json:"peerCertSANs,omitempty"`
   288  }
   289  
   290  // ExternalEtcd describes an external etcd cluster.
   291  // Kubeadm has no knowledge of where certificate files live and they must be supplied.
   292  type ExternalEtcd struct {
   293  	// Endpoints of etcd members. Required for ExternalEtcd.
   294  	Endpoints []string `json:"endpoints"`
   295  
   296  	// CAFile is an SSL Certificate Authority file used to secure etcd communication.
   297  	// Required if using a TLS connection.
   298  	CAFile string `json:"caFile"`
   299  
   300  	// CertFile is an SSL certification file used to secure etcd communication.
   301  	// Required if using a TLS connection.
   302  	CertFile string `json:"certFile"`
   303  
   304  	// KeyFile is an SSL key file used to secure etcd communication.
   305  	// Required if using a TLS connection.
   306  	KeyFile string `json:"keyFile"`
   307  }
   308  
   309  // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
   310  
   311  // JoinConfiguration contains elements describing a particular node.
   312  type JoinConfiguration struct {
   313  	metav1.TypeMeta `json:",inline"`
   314  
   315  	// NodeRegistration holds fields that relate to registering the new control-plane node to the cluster
   316  	NodeRegistration NodeRegistrationOptions `json:"nodeRegistration"`
   317  
   318  	// CACertPath is the path to the SSL certificate authority used to
   319  	// secure comunications between node and control-plane.
   320  	// Defaults to "/etc/kubernetes/pki/ca.crt".
   321  	// +optional
   322  	// TODO: revisit when there is defaulting from k/k
   323  	CACertPath string `json:"caCertPath,omitempty"`
   324  
   325  	// Discovery specifies the options for the kubelet to use during the TLS Bootstrap process
   326  	// +optional
   327  	// TODO: revisit when there is defaulting from k/k
   328  	Discovery Discovery `json:"discovery,omitempty"`
   329  
   330  	// ControlPlane defines the additional control plane instance to be deployed on the joining node.
   331  	// If nil, no additional control plane instance will be deployed.
   332  	ControlPlane *JoinControlPlane `json:"controlPlane,omitempty"`
   333  }
   334  
   335  // JoinControlPlane contains elements describing an additional control plane instance to be deployed on the joining node.
   336  type JoinControlPlane struct {
   337  	// LocalAPIEndpoint represents the endpoint of the API server instance to be deployed on this node.
   338  	LocalAPIEndpoint APIEndpoint `json:"localAPIEndpoint,omitempty"`
   339  }
   340  
   341  // Discovery specifies the options for the kubelet to use during the TLS Bootstrap process
   342  type Discovery struct {
   343  	// BootstrapToken is used to set the options for bootstrap token based discovery
   344  	// BootstrapToken and File are mutually exclusive
   345  	BootstrapToken *BootstrapTokenDiscovery `json:"bootstrapToken,omitempty"`
   346  
   347  	// File is used to specify a file or URL to a kubeconfig file from which to load cluster information
   348  	// BootstrapToken and File are mutually exclusive
   349  	File *FileDiscovery `json:"file,omitempty"`
   350  
   351  	// TLSBootstrapToken is a token used for TLS bootstrapping.
   352  	// If .BootstrapToken is set, this field is defaulted to .BootstrapToken.Token, but can be overridden.
   353  	// If .File is set, this field **must be set** in case the KubeConfigFile does not contain any other authentication information
   354  	// +optional
   355  	// TODO: revisit when there is defaulting from k/k
   356  	TLSBootstrapToken string `json:"tlsBootstrapToken,omitempty"`
   357  
   358  	// Timeout modifies the discovery timeout
   359  	Timeout *metav1.Duration `json:"timeout,omitempty"`
   360  }
   361  
   362  // BootstrapTokenDiscovery is used to set the options for bootstrap token based discovery
   363  type BootstrapTokenDiscovery struct {
   364  	// Token is a token used to validate cluster information
   365  	// fetched from the control-plane.
   366  	Token string `json:"token"`
   367  
   368  	// APIServerEndpoint is an IP or domain name to the API server from which info will be fetched.
   369  	APIServerEndpoint string `json:"apiServerEndpoint,omitempty"`
   370  
   371  	// CACertHashes specifies a set of public key pins to verify
   372  	// when token-based discovery is used. The root CA found during discovery
   373  	// must match one of these values. Specifying an empty set disables root CA
   374  	// pinning, which can be unsafe. Each hash is specified as "<type>:<value>",
   375  	// where the only currently supported type is "sha256". This is a hex-encoded
   376  	// SHA-256 hash of the Subject Public Key Info (SPKI) object in DER-encoded
   377  	// ASN.1. These hashes can be calculated using, for example, OpenSSL:
   378  	// openssl x509 -pubkey -in ca.crt openssl rsa -pubin -outform der 2>&/dev/null | openssl dgst -sha256 -hex
   379  	CACertHashes []string `json:"caCertHashes,omitempty"`
   380  
   381  	// UnsafeSkipCAVerification allows token-based discovery
   382  	// without CA verification via CACertHashes. This can weaken
   383  	// the security of kubeadm since other nodes can impersonate the control-plane.
   384  	UnsafeSkipCAVerification bool `json:"unsafeSkipCAVerification"`
   385  }
   386  
   387  // FileDiscovery is used to specify a file or URL to a kubeconfig file from which to load cluster information
   388  type FileDiscovery struct {
   389  	// KubeConfigPath is used to specify the actual file path or URL to the kubeconfig file from which to load cluster information
   390  	KubeConfigPath string `json:"kubeConfigPath"`
   391  }
   392  
   393  // HostPathMount contains elements describing volumes that are mounted from the
   394  // host.
   395  type HostPathMount struct {
   396  	// Name of the volume inside the pod template.
   397  	Name string `json:"name"`
   398  	// HostPath is the path in the host that will be mounted inside
   399  	// the pod.
   400  	HostPath string `json:"hostPath"`
   401  	// MountPath is the path inside the pod where hostPath will be mounted.
   402  	MountPath string `json:"mountPath"`
   403  	// ReadOnly controls write access to the volume
   404  	ReadOnly bool `json:"readOnly,omitempty"`
   405  	// PathType is the type of the HostPath.
   406  	PathType v1.HostPathType `json:"pathType,omitempty"`
   407  }