2019-01-09 16:54:15 +00:00
package cmds
import (
2019-09-03 23:41:54 +00:00
"fmt"
"github.com/rancher/k3s/pkg/daemons/config"
2019-01-09 16:54:15 +00:00
"github.com/urfave/cli"
)
type Server struct {
2019-10-15 21:17:26 +00:00
ClusterCIDR string
2019-10-27 05:53:25 +00:00
AgentToken string
AgentTokenFile string
Token string
TokenFile string
2019-10-15 21:17:26 +00:00
ServiceCIDR string
ClusterDNS string
ClusterDomain string
HTTPSPort int
DataDir string
DisableAgent bool
KubeConfigOutput string
KubeConfigMode string
TLSSan cli . StringSlice
BindAddress string
ExtraAPIArgs cli . StringSlice
ExtraSchedulerArgs cli . StringSlice
ExtraControllerArgs cli . StringSlice
ExtraCloudControllerArgs cli . StringSlice
Rootless bool
StorageEndpoint string
StorageCAFile string
StorageCertFile string
StorageKeyFile string
AdvertiseIP string
AdvertisePort int
DisableScheduler bool
2019-10-27 05:53:25 +00:00
ServerURL string
2019-10-15 21:17:26 +00:00
FlannelBackend string
DefaultLocalStoragePath string
DisableCCM bool
2019-10-17 21:46:15 +00:00
DisableNPC bool
2019-10-27 05:53:25 +00:00
ClusterInit bool
ClusterReset bool
2019-01-09 16:54:15 +00:00
}
var ServerConfig Server
func NewServerCommand ( action func ( * cli . Context ) error ) cli . Command {
return cli . Command {
Name : "server" ,
Usage : "Run management server" ,
UsageText : appName + " server [OPTIONS]" ,
Action : action ,
Flags : [ ] cli . Flag {
2019-08-08 05:45:54 +00:00
VLevel ,
VModule ,
LogFile ,
AlsoLogToStderr ,
2019-03-31 00:10:23 +00:00
cli . StringFlag {
Name : "bind-address" ,
2019-10-27 05:53:25 +00:00
Usage : "(listener) k3s bind address (default: 0.0.0.0)" ,
2019-03-31 00:10:23 +00:00
Destination : & ServerConfig . BindAddress ,
} ,
2019-01-09 16:54:15 +00:00
cli . IntFlag {
Name : "https-listen-port" ,
2019-10-27 05:53:25 +00:00
Usage : "(listener) HTTPS listen port" ,
2019-01-09 16:54:15 +00:00
Value : 6443 ,
Destination : & ServerConfig . HTTPSPort ,
} ,
2019-10-27 05:53:25 +00:00
cli . StringFlag {
Name : "advertise-address" ,
Usage : "(listener) IP address that apiserver uses to advertise to members of the cluster (default: node-external-ip/node-ip)" ,
Destination : & ServerConfig . AdvertiseIP ,
} ,
2019-01-09 16:54:15 +00:00
cli . IntFlag {
2019-10-27 05:53:25 +00:00
Name : "advertise-port" ,
Usage : "(listener) Port that apiserver uses to advertise to members of the cluster (default: listen-port)" ,
Destination : & ServerConfig . AdvertisePort ,
} ,
cli . StringSliceFlag {
Name : "tls-san" ,
Usage : "(listener) Add additional hostname or IP as a Subject Alternative Name in the TLS cert" ,
Value : & ServerConfig . TLSSan ,
2019-01-09 16:54:15 +00:00
} ,
cli . StringFlag {
Name : "data-dir,d" ,
2019-10-27 05:53:25 +00:00
Usage : "(data) Folder to hold state default /var/lib/rancher/k3s or ${HOME}/.rancher/k3s if not root" ,
2019-01-09 16:54:15 +00:00
Destination : & ServerConfig . DataDir ,
} ,
cli . StringFlag {
Name : "cluster-cidr" ,
2019-10-27 05:53:25 +00:00
Usage : "(networking) Network CIDR to use for pod IPs" ,
2019-01-09 16:54:15 +00:00
Destination : & ServerConfig . ClusterCIDR ,
2019-03-04 05:25:02 +00:00
Value : "10.42.0.0/16" ,
2019-01-09 16:54:15 +00:00
} ,
2019-03-06 10:37:03 +00:00
cli . StringFlag {
Name : "service-cidr" ,
2019-10-27 05:53:25 +00:00
Usage : "(networking) Network CIDR to use for services IPs" ,
2019-03-06 10:37:03 +00:00
Destination : & ServerConfig . ServiceCIDR ,
Value : "10.43.0.0/16" ,
} ,
2019-03-06 11:16:04 +00:00
cli . StringFlag {
Name : "cluster-dns" ,
2019-10-27 05:53:25 +00:00
Usage : "(networking) Cluster IP for coredns service. Should be in your service-cidr range (default: 10.43.0.10)" ,
2019-03-06 11:16:04 +00:00
Destination : & ServerConfig . ClusterDNS ,
2019-03-06 18:41:07 +00:00
Value : "" ,
2019-03-06 11:16:04 +00:00
} ,
2019-04-12 06:06:35 +00:00
cli . StringFlag {
Name : "cluster-domain" ,
2019-10-27 05:53:25 +00:00
Usage : "(networking) Cluster Domain" ,
2019-04-12 06:06:35 +00:00
Destination : & ServerConfig . ClusterDomain ,
Value : "cluster.local" ,
} ,
2019-10-27 05:53:25 +00:00
cli . StringFlag {
Name : "flannel-backend" ,
Usage : fmt . Sprintf ( "(networking) One of '%s', '%s', '%s', or '%s'" , config . FlannelBackendNone , config . FlannelBackendVXLAN , config . FlannelBackendIPSEC , config . FlannelBackendWireguard ) ,
Destination : & ServerConfig . FlannelBackend ,
Value : config . FlannelBackendVXLAN ,
} ,
cli . StringFlag {
Name : "token,t" ,
Usage : "(cluster) Shared secret used to join a server or agent to a cluster" ,
Destination : & ServerConfig . Token ,
EnvVar : "K3S_CLUSTER_SECRET,K3S_TOKEN" ,
} ,
cli . StringFlag {
Name : "token-file" ,
Usage : "(cluster) File containing the cluster-secret/token" ,
Destination : & ServerConfig . TokenFile ,
EnvVar : "K3S_TOKEN_FILE" ,
} ,
cli . StringFlag {
Name : "agent-token" ,
Usage : "(cluster) Shared secret used to join agents to the cluster, but not agents" ,
Destination : & ServerConfig . AgentToken ,
EnvVar : "K3S_AGENT_TOKEN" ,
} ,
cli . StringFlag {
Name : "agent-token-file" ,
Usage : "(cluster) File containing the agent secret" ,
Destination : & ServerConfig . AgentTokenFile ,
EnvVar : "K3S_AGENT_TOKEN_FILE" ,
} ,
cli . StringFlag {
Name : "server,s" ,
Usage : "(cluster) Server to connect to, used to join a cluster" ,
EnvVar : "K3S_URL" ,
Destination : & ServerConfig . ServerURL ,
} ,
cli . BoolFlag {
Name : "new-cluster" ,
Hidden : hideDqlite ,
Usage : "(cluster) Initialize new cluster master" ,
EnvVar : "K3S_CLUSTER_INIT" ,
Destination : & ServerConfig . ClusterInit ,
} ,
cli . BoolFlag {
Name : "reset-cluster" ,
Hidden : hideDqlite ,
Usage : "(cluster) Forget all peers and become a single cluster new cluster master" ,
EnvVar : "K3S_CLUSTER_RESET" ,
Destination : & ServerConfig . ClusterReset ,
2019-01-22 21:14:58 +00:00
} ,
cli . StringFlag {
Name : "write-kubeconfig,o" ,
2019-10-27 05:53:25 +00:00
Usage : "(client) Write kubeconfig for admin client to this file" ,
2019-01-22 21:14:58 +00:00
Destination : & ServerConfig . KubeConfigOutput ,
EnvVar : "K3S_KUBECONFIG_OUTPUT" ,
} ,
cli . StringFlag {
Name : "write-kubeconfig-mode" ,
2019-10-27 05:53:25 +00:00
Usage : "(client) Write kubeconfig with this mode" ,
2019-01-22 21:14:58 +00:00
Destination : & ServerConfig . KubeConfigMode ,
EnvVar : "K3S_KUBECONFIG_MODE" ,
} ,
2019-04-05 00:43:00 +00:00
cli . StringSliceFlag {
Name : "kube-apiserver-arg" ,
2019-10-27 05:53:25 +00:00
Usage : "(flags) Customized flag for kube-apiserver process" ,
2019-04-05 00:43:00 +00:00
Value : & ServerConfig . ExtraAPIArgs ,
} ,
cli . StringSliceFlag {
Name : "kube-scheduler-arg" ,
2019-10-27 05:53:25 +00:00
Usage : "(flags) Customized flag for kube-scheduler process" ,
2019-04-05 00:43:00 +00:00
Value : & ServerConfig . ExtraSchedulerArgs ,
} ,
cli . StringSliceFlag {
2019-10-27 05:53:25 +00:00
Name : "kube-controller-manager-arg" ,
Usage : "(flags) Customized flag for kube-controller-manager process" ,
2019-04-05 00:43:00 +00:00
Value : & ServerConfig . ExtraControllerArgs ,
} ,
2019-10-15 21:17:26 +00:00
cli . StringSliceFlag {
2019-10-27 05:53:25 +00:00
Name : "kube-cloud-controller-manager-arg" ,
Usage : "(flags) Customized flag for kube-cloud-controller-manager process" ,
2019-10-15 21:17:26 +00:00
Value : & ServerConfig . ExtraCloudControllerArgs ,
} ,
2019-05-15 23:05:24 +00:00
cli . StringFlag {
Name : "storage-endpoint" ,
2019-10-27 05:53:25 +00:00
Usage : "(db) Specify etcd, Mysql, Postgres, or Sqlite (default) data source name" ,
2019-05-15 23:05:24 +00:00
Destination : & ServerConfig . StorageEndpoint ,
EnvVar : "K3S_STORAGE_ENDPOINT" ,
} ,
2019-06-11 22:48:47 +00:00
cli . StringFlag {
Name : "storage-cafile" ,
2019-10-27 05:53:25 +00:00
Usage : "(db) SSL Certificate Authority file used to secure storage backend communication" ,
2019-06-11 22:48:47 +00:00
Destination : & ServerConfig . StorageCAFile ,
EnvVar : "K3S_STORAGE_CAFILE" ,
} ,
cli . StringFlag {
Name : "storage-certfile" ,
2019-10-27 05:53:25 +00:00
Usage : "(db) SSL certification file used to secure storage backend communication" ,
2019-06-11 22:48:47 +00:00
Destination : & ServerConfig . StorageCertFile ,
EnvVar : "K3S_STORAGE_CERTFILE" ,
} ,
cli . StringFlag {
Name : "storage-keyfile" ,
2019-10-27 05:53:25 +00:00
Usage : "(db) SSL key file used to secure storage backend communication" ,
2019-06-11 22:48:47 +00:00
Destination : & ServerConfig . StorageKeyFile ,
EnvVar : "K3S_STORAGE_KEYFILE" ,
} ,
2019-05-29 18:53:51 +00:00
cli . StringFlag {
2019-10-27 05:53:25 +00:00
Name : "default-local-storage-path" ,
Usage : "(storage) Default local storage path for local provisioner storage class" ,
Destination : & ServerConfig . DefaultLocalStoragePath ,
2019-05-29 18:53:51 +00:00
} ,
2019-10-27 05:53:25 +00:00
cli . StringSliceFlag {
Name : "no-deploy" ,
2019-11-05 17:11:08 +00:00
Usage : "(components) Do not deploy packaged components (valid items: coredns, servicelb, traefik, local-storage, metrics-server)" ,
2019-05-29 18:53:51 +00:00
} ,
2019-07-12 16:59:03 +00:00
cli . BoolFlag {
Name : "disable-scheduler" ,
2019-10-27 05:53:25 +00:00
Usage : "(components) Disable Kubernetes default scheduler" ,
2019-07-12 16:59:03 +00:00
Destination : & ServerConfig . DisableScheduler ,
} ,
2019-10-15 21:17:26 +00:00
cli . BoolFlag {
Name : "disable-cloud-controller" ,
2019-10-27 05:53:25 +00:00
Usage : "(components) Disable k3s default cloud controller manager" ,
2019-10-15 21:17:26 +00:00
Destination : & ServerConfig . DisableCCM ,
} ,
2019-10-17 21:46:15 +00:00
cli . BoolFlag {
Name : "disable-network-policy" ,
2019-10-27 05:53:25 +00:00
Usage : "(components) Disable k3s default network policy controller" ,
2019-10-17 21:46:15 +00:00
Destination : & ServerConfig . DisableNPC ,
} ,
2019-01-09 16:54:15 +00:00
NodeNameFlag ,
2019-10-27 05:53:25 +00:00
NodeLabels ,
NodeTaints ,
2019-03-02 00:10:18 +00:00
DockerFlag ,
2019-03-04 06:29:06 +00:00
CRIEndpointFlag ,
2019-05-03 17:36:12 +00:00
PauseImageFlag ,
2019-10-27 05:53:25 +00:00
PrivateRegistryFlag ,
NodeIPFlag ,
NodeExternalIPFlag ,
2019-03-26 22:15:16 +00:00
ResolvConfFlag ,
2019-10-27 05:53:25 +00:00
FlannelIfaceFlag ,
FlannelConfFlag ,
2019-04-05 00:43:00 +00:00
ExtraKubeletArgs ,
ExtraKubeProxyArgs ,
2019-10-27 05:53:25 +00:00
cli . BoolFlag {
Name : "rootless" ,
Usage : "(experimental) Run rootless" ,
Destination : & ServerConfig . Rootless ,
} ,
// Hidden/Deprecated flags below
FlannelFlag ,
cli . StringFlag {
Name : "cluster-secret" ,
Usage : "(deprecated) use --token" ,
Destination : & ServerConfig . Token ,
EnvVar : "K3S_CLUSTER_SECRET" ,
} ,
cli . BoolFlag {
Name : "disable-agent" ,
Usage : "Do not run a local agent and register a local kubelet" ,
Hidden : true ,
Destination : & ServerConfig . DisableAgent ,
} ,
cli . StringSliceFlag {
Hidden : true ,
Name : "kube-controller-arg" ,
Usage : "(flags) Customized flag for kube-controller-manager process" ,
Value : & ServerConfig . ExtraControllerArgs ,
} ,
cli . StringSliceFlag {
Hidden : true ,
Name : "kube-cloud-controller-arg" ,
Usage : "(flags) Customized flag for kube-cloud-controller-manager process" ,
Value : & ServerConfig . ExtraCloudControllerArgs ,
} ,
2019-01-09 16:54:15 +00:00
} ,
}
}