cmd.go 4.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. Copyright 2016 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package cmd
  14. import (
  15. "io"
  16. "github.com/lithammer/dedent"
  17. "github.com/spf13/cobra"
  18. "k8s.io/kubernetes/cmd/kubeadm/app/cmd/alpha"
  19. "k8s.io/kubernetes/cmd/kubeadm/app/cmd/options"
  20. "k8s.io/kubernetes/cmd/kubeadm/app/cmd/upgrade"
  21. kubeadmutil "k8s.io/kubernetes/cmd/kubeadm/app/util"
  22. // Register the kubeadm configuration types because CLI flag generation
  23. // depends on the generated defaults.
  24. )
  25. // NewKubeadmCommand returns cobra.Command to run kubeadm command
  26. func NewKubeadmCommand(in io.Reader, out, err io.Writer) *cobra.Command {
  27. var rootfsPath string
  28. cmds := &cobra.Command{
  29. Use: "kubeadm",
  30. Short: "kubeadm: easily bootstrap a secure Kubernetes cluster",
  31. Long: dedent.Dedent(`
  32. ┌──────────────────────────────────────────────────────────┐
  33. │ KUBEADM │
  34. │ Easily bootstrap a secure Kubernetes cluster │
  35. │ │
  36. │ Please give us feedback at: │
  37. │ https://github.com/kubernetes/kubeadm/issues │
  38. └──────────────────────────────────────────────────────────┘
  39. Example usage:
  40. Create a two-machine cluster with one control-plane node
  41. (which controls the cluster), and one worker node
  42. (where your workloads, like Pods and Deployments run).
  43. ┌──────────────────────────────────────────────────────────┐
  44. │ On the first machine: │
  45. ├──────────────────────────────────────────────────────────┤
  46. │ control-plane# kubeadm init │
  47. └──────────────────────────────────────────────────────────┘
  48. ┌──────────────────────────────────────────────────────────┐
  49. │ On the second machine: │
  50. ├──────────────────────────────────────────────────────────┤
  51. │ worker# kubeadm join <arguments-returned-from-init> │
  52. └──────────────────────────────────────────────────────────┘
  53. You can then repeat the second step on as many other machines as you like.
  54. `),
  55. SilenceErrors: true,
  56. SilenceUsage: true,
  57. PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
  58. if rootfsPath != "" {
  59. if err := kubeadmutil.Chroot(rootfsPath); err != nil {
  60. return err
  61. }
  62. }
  63. return nil
  64. },
  65. }
  66. cmds.ResetFlags()
  67. cmds.AddCommand(NewCmdCompletion(out, ""))
  68. cmds.AddCommand(NewCmdConfig(out))
  69. cmds.AddCommand(NewCmdInit(out, nil))
  70. cmds.AddCommand(NewCmdJoin(out, nil))
  71. cmds.AddCommand(NewCmdReset(in, out, nil))
  72. cmds.AddCommand(NewCmdVersion(out))
  73. cmds.AddCommand(NewCmdToken(out, err))
  74. cmds.AddCommand(upgrade.NewCmdUpgrade(out))
  75. cmds.AddCommand(alpha.NewCmdAlpha(in, out))
  76. options.AddKubeadmOtherFlags(cmds.PersistentFlags(), &rootfsPath)
  77. return cmds
  78. }