Skip to content

Commit

Permalink
yurtctl add init subcommand. (#430)
Browse files Browse the repository at this point in the history
  • Loading branch information
zyjhtangtang authored Sep 7, 2021
1 parent 1c52843 commit da0cd00
Show file tree
Hide file tree
Showing 23 changed files with 1,593 additions and 427 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ To uninstall OpenYurt and revert back to the original Kubernetes cluster setting
_output/bin/yurtctl revert
```

To create OpenYurt cluster, you can run the following command:

```bash
_output/bin/yurtctl init
```

To join nodes to OpenYurt, you can run the following command:
```bash
_output/bin/yurtctl join
Expand Down
10 changes: 10 additions & 0 deletions docs/tutorial/yurtctl.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,16 @@ Note that before performing the uninstall, please make sure all edge nodes are r
In addition, the path of the kubelet service configuration can be set by the option `--kubeadm-conf-path`,
and the path of the directory on edge node containing static pod files can be set by the option `--pod-manifest-path`.

## Create OpenYurt cluster
`yurtctl init` will create an OpenYurt cluster, but the user needs to install the runtime in advance and ensure that the swap partition of the node has been closed.

Using `yurtctl` to create an OpenYurt cluster can be done by doing the following:
```
$ _output/bin/yurtctl init --image-repository=registry.cn-hangzhou.aliyuncs.com/google_containers --kubernetes-version=v1.18.8 --pod-network-cidr=10.244.0.0/16
```
In addition, the OpenYurt components version can be set by the option `--yurt-version`,
and the OpenYurt components image registry can be set by the option `--yurt-image-registry`.

## Join Edge-Node/Cloud-Node to OpenYurt

`yurtctl join` will automatically install the corresponding kubelet according to the cluster version, but the user needs to install the runtime in advance and ensure that the swap partition of the node has been closed.
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ require (
k8s.io/api v0.19.7
k8s.io/apimachinery v0.19.7
k8s.io/apiserver v0.18.8
k8s.io/cli-runtime v0.18.8
k8s.io/client-go v0.19.2
k8s.io/cluster-bootstrap v0.0.0
k8s.io/component-base v0.18.8
k8s.io/klog v1.0.0
k8s.io/klog/v2 v2.0.0
k8s.io/kubectl v0.0.0
k8s.io/kubelet v0.0.0
k8s.io/kubernetes v1.18.8
k8s.io/utils v0.0.0-20200603063816-c1c6865ac451
Expand Down
5 changes: 5 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/GoogleCloudPlatform/k8s-cloud-provider v0.0.0-20190822182118-27a4ced34534/go.mod h1:iroGtC8B3tQiqtds1l+mgk/BBOrxbqjH+eUfFQYRc14=
github.com/JeffAshton/win_pdh v0.0.0-20161109143554-76bb4ee9f0ab/go.mod h1:3VYc5hodBMJ5+l/7J4xAyMeuM2PNuepvHlGs8yilUCA=
github.com/MakeNowJust/heredoc v0.0.0-20170808103936-bb23615498cd h1:sjQovDkwrZp8u+gxLtPgKGjk5hCxuy2hrRejBTA9xFU=
github.com/MakeNowJust/heredoc v0.0.0-20170808103936-bb23615498cd/go.mod h1:64YHyfSL2R96J44Nlwm39UHepQbyR5q10x7iYa1ks2E=
github.com/Microsoft/go-winio v0.4.14 h1:+hMXMk01us9KgxGb7ftKQt2Xpf5hH/yky+TDA+qxleU=
github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA=
Expand Down Expand Up @@ -77,6 +78,7 @@ github.com/caddyserver/caddy v1.0.3/go.mod h1:G+ouvOY32gENkJC+jhgl62TyhvqEsFaDiZ
github.com/cenkalti/backoff v2.1.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/cespare/prettybench v0.0.0-20150116022406-03b8cfe5406c/go.mod h1:Xe6ZsFhtM8HrDku0pxJ3/Lr51rwykrzgFwpmTzleatY=
github.com/chai2010/gettext-go v0.0.0-20160711120539-c6fed771bfd5 h1:7aWHqerlJ41y6FOsEUvknqgXnGmJyJSbjhAWq5pO4F8=
github.com/chai2010/gettext-go v0.0.0-20160711120539-c6fed771bfd5/go.mod h1:/iP1qXHoty45bqomnu2LM+VVyAEdWN+vtSHGlQgyxbw=
github.com/checkpoint-restore/go-criu v0.0.0-20181120144056-17b0214f6c48/go.mod h1:TrMrLQfeENAPYPRsJuq3jsqdlRh3lvi6trTZJG8+tho=
github.com/cheekybits/genny v0.0.0-20170328200008-9127e812e1e9/go.mod h1:+tQajlRqAUrPI7DOSpB0XAqZYtQakVtB7wXkRAgjxjQ=
Expand Down Expand Up @@ -149,6 +151,7 @@ github.com/euank/go-kmsg-parser v2.0.0+incompatible/go.mod h1:MhmAMZ8V4CYH4ybgdR
github.com/evanphx/json-patch v0.0.0-20200808040245-162e5629780b/go.mod h1:NAJj0yf/KaRKURN6nyi7A9IZydMivZEm9oQLWNjfKDc=
github.com/evanphx/json-patch v4.5.0+incompatible h1:ouOWdg56aJriqS0huScTkVXPC5IcNrDCXZ6OoTAWu7M=
github.com/evanphx/json-patch v4.5.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d h1:105gxyaGwCFad8crR9dcMQWvV9Hvulu6hwUh4tWPJnM=
github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d/go.mod h1:ZZMPRZwes7CROmyNKgQzC3XPs6L/G2EJLHddWejkmf4=
github.com/fatih/camelcase v1.0.0/go.mod h1:yN2Sb0lFhZJUdVvtELVWefmrXpuZESvPmqwoZc+/fpc=
github.com/fatih/color v1.6.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
Expand Down Expand Up @@ -450,6 +453,7 @@ github.com/mistifyio/go-zfs v2.1.1+incompatible/go.mod h1:8AuVvqP/mXw1px98n46wfv
github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/go-ps v0.0.0-20170309133038-4fdf99ab2936/go.mod h1:r1VsdOzOPt1ZSrGZWFoNhsAedKnEd6r9Np1+5blZCWk=
github.com/mitchellh/go-wordwrap v1.0.0 h1:6GlHJ/LTGMrIJbwgdqdl2eEH8o+Exx/0m8ir9Gns0u4=
github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo=
github.com/mitchellh/mapstructure v0.0.0-20180220230111-00c29f56e238/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
Expand Down Expand Up @@ -547,6 +551,7 @@ github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rubiojr/go-vhd v0.0.0-20160810183302-0bfd3b39853c/go.mod h1:DM5xW0nvfNNm2uytzsvhI3OnX8uzaRAg8UX/CnDqbto=
github.com/russross/blackfriday v0.0.0-20170610170232-067529f716f4/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
github.com/russross/blackfriday v1.5.2 h1:HyvC0ARfnZBqnXwABFeSZHpKvJHJJfPz81GNueLj0oo=
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/ryanuber/go-glob v0.0.0-20170128012129-256dc444b735/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc=
Expand Down
6 changes: 4 additions & 2 deletions pkg/yurtctl/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import (
"fmt"
"os"

"github.com/spf13/cobra"
flag "github.com/spf13/pflag"
"k8s.io/klog"

"github.com/openyurtio/openyurt/pkg/projectinfo"
Expand All @@ -32,6 +30,9 @@ import (
"github.com/openyurtio/openyurt/pkg/yurtctl/cmd/markautonomous"
"github.com/openyurtio/openyurt/pkg/yurtctl/cmd/reset"
"github.com/openyurtio/openyurt/pkg/yurtctl/cmd/revert"
"github.com/openyurtio/openyurt/pkg/yurtctl/cmd/yurtinit"
"github.com/spf13/cobra"
flag "github.com/spf13/pflag"
)

// NewYurtctlCommand creates a new yurtctl command
Expand All @@ -52,6 +53,7 @@ func NewYurtctlCommand() *cobra.Command {
cmds.AddCommand(clusterinfo.NewClusterInfoCmd())
cmds.AddCommand(join.NewCmdJoin(os.Stdout, nil))
cmds.AddCommand(reset.NewCmdReset(os.Stdin, os.Stdout, nil))
cmds.AddCommand(yurtinit.NewCmdInit(os.Stdout, nil))

klog.InitFlags(nil)
// goflag.Parse()
Expand Down
186 changes: 5 additions & 181 deletions pkg/yurtctl/cmd/convert/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"github.com/spf13/pflag"

"github.com/openyurtio/openyurt/pkg/projectinfo"
"github.com/openyurtio/openyurt/pkg/yurtctl/constants"
"github.com/openyurtio/openyurt/pkg/yurtctl/lock"
kubeutil "github.com/openyurtio/openyurt/pkg/yurtctl/util/kubernetes"
strutil "github.com/openyurtio/openyurt/pkg/yurtctl/util/strings"
Expand Down Expand Up @@ -327,35 +326,10 @@ func (co *ConvertOptions) RunConvert() (err error) {
}

// 3. deploy yurt controller manager
// create a service account for yurt-controller-manager
err = kubeutil.CreateServiceAccountFromYaml(co.clientSet,
"kube-system", constants.YurtControllerManagerServiceAccount)
if err != nil {
return
}
// create the clusterrole
err = kubeutil.CreateClusterRoleFromYaml(co.clientSet,
constants.YurtControllerManagerClusterRole)
if err != nil {
return err
}
// bind the clusterrole
err = kubeutil.CreateClusterRoleBindingFromYaml(co.clientSet,
constants.YurtControllerManagerClusterRoleBinding)
if err != nil {
return
}
// create the yurt-controller-manager deployment
err = kubeutil.CreateDeployFromYaml(co.clientSet,
"kube-system",
constants.YurtControllerManagerDeployment,
map[string]string{
"image": co.YurtControllerManagerImage,
"edgeNodeLabel": projectinfo.GetEdgeWorkerLabelKey()})
if err != nil {
if err = kubeutil.DeployYurtControllerManager(co.clientSet, co.YurtControllerManagerImage); err != nil {
klog.Errorf("fail to deploy yurtcontrollermanager: %s", err)
return
}

// 4. disable node-controller
ctx := map[string]string{
"action": "disable",
Expand All @@ -370,7 +344,7 @@ func (co *ConvertOptions) RunConvert() (err error) {

// 5. deploy the yurttunnel if required
if co.DeployTunnel {
if err = deployYurttunnelServer(co.clientSet,
if err = kubeutil.DeployYurttunnelServer(co.clientSet,
co.CloudNodes,
co.YurttunnelServerImage,
co.SystemArchitecture); err != nil {
Expand All @@ -379,7 +353,7 @@ func (co *ConvertOptions) RunConvert() (err error) {
}
klog.Info("yurt-tunnel-server is deployed")
// we will deploy yurt-tunnel-agent on every edge node
if err = deployYurttunnelAgent(co.clientSet,
if err = kubeutil.DeployYurttunnelAgent(co.clientSet,
edgeNodeNames,
co.YurttunnelAgentImage); err != nil {
err = fmt.Errorf("fail to deploy the yurt-tunnel-agent: %s", err)
Expand All @@ -397,7 +371,7 @@ func (co *ConvertOptions) RunConvert() (err error) {

//7. deploy the yurtappmanager if required
if co.EnableAppManager {
if err = deployYurtAppManager(co.clientSet,
if err = kubeutil.DeployYurtAppManager(co.clientSet,
co.YurtAppManagerImage,
co.yurtAppManagerClientSet,
co.SystemArchitecture); err != nil {
Expand Down Expand Up @@ -437,156 +411,6 @@ func (co *ConvertOptions) RunConvert() (err error) {
return
}

func deployYurtAppManager(
client *kubernetes.Clientset,
yurtappmanagerImage string,
yurtAppManagerClient dynamic.Interface,
systemArchitecture string) error {

// 1.create the YurtAppManagerCustomResourceDefinition
// 1.1 nodepool
if err := kubeutil.CreateCRDFromYaml(client, yurtAppManagerClient, "", []byte(constants.YurtAppManagerNodePool)); err != nil {
return err
}

// 1.2 uniteddeployment
if err := kubeutil.CreateCRDFromYaml(client, yurtAppManagerClient, "", []byte(constants.YurtAppManagerUnitedDeployment)); err != nil {
return err
}

// 2. create the YurtAppManagerRole
if err := kubeutil.CreateRoleFromYaml(client, "kube-system",
constants.YurtAppManagerRole); err != nil {
return err
}

// 3. create the ClusterRole
if err := kubeutil.CreateClusterRoleFromYaml(client,
constants.YurtAppManagerClusterRole); err != nil {
return err
}

// 4. create the RoleBinding
if err := kubeutil.CreateRoleBindingFromYaml(client, "kube-system",
constants.YurtAppManagerRolebinding); err != nil {
return err
}

// 5. create the ClusterRoleBinding
if err := kubeutil.CreateClusterRoleBindingFromYaml(client,
constants.YurtAppManagerClusterRolebinding); err != nil {
return err
}

// 6. create the Secret
if err := kubeutil.CreateSecretFromYaml(client, "kube-system",
constants.YurtAppManagerSecret); err != nil {
return err
}

// 7. create the Service
if err := kubeutil.CreateServiceFromYaml(client,
constants.YurtAppManagerService); err != nil {
return err
}

// 8. create the Deployment
if err := kubeutil.CreateDeployFromYaml(client,
"kube-system",
constants.YurtAppManagerDeployment,
map[string]string{
"image": yurtappmanagerImage,
"arch": systemArchitecture,
"edgeWorkerLabel": projectinfo.GetEdgeWorkerLabelKey()}); err != nil {
return err
}

// 9. create the YurtAppManagerMutatingWebhookConfiguration
if err := kubeutil.CreateMutatingWebhookConfigurationFromYaml(client,
constants.YurtAppManagerMutatingWebhookConfiguration); err != nil {
return err
}

// 10. create the YurtAppManagerValidatingWebhookConfiguration
if err := kubeutil.CreateValidatingWebhookConfigurationFromYaml(client,
constants.YurtAppManagerValidatingWebhookConfiguration); err != nil {
return err
}

return nil
}

func deployYurttunnelServer(
client *kubernetes.Clientset,
cloudNodes []string,
yurttunnelServerImage string,
systemArchitecture string) error {
// 1. create the ClusterRole
if err := kubeutil.CreateClusterRoleFromYaml(client,
constants.YurttunnelServerClusterRole); err != nil {
return err
}

// 2. create the ServiceAccount
if err := kubeutil.CreateServiceAccountFromYaml(client, "kube-system",
constants.YurttunnelServerServiceAccount); err != nil {
return err
}

// 3. create the ClusterRoleBinding
if err := kubeutil.CreateClusterRoleBindingFromYaml(client,
constants.YurttunnelServerClusterRolebinding); err != nil {
return err
}

// 4. create the Service
if err := kubeutil.CreateServiceFromYaml(client,
constants.YurttunnelServerService); err != nil {
return err
}

// 5. create the internal Service(type=ClusterIP)
if err := kubeutil.CreateServiceFromYaml(client,
constants.YurttunnelServerInternalService); err != nil {
return err
}

// 6. create the Configmap
if err := kubeutil.CreateConfigMapFromYaml(client,
"kube-system",
constants.YurttunnelServerConfigMap); err != nil {
return err
}

// 7. create the Deployment
if err := kubeutil.CreateDeployFromYaml(client,
"kube-system",
constants.YurttunnelServerDeployment,
map[string]string{
"image": yurttunnelServerImage,
"arch": systemArchitecture,
"edgeWorkerLabel": projectinfo.GetEdgeWorkerLabelKey()}); err != nil {
return err
}

return nil
}

func deployYurttunnelAgent(
client *kubernetes.Clientset,
tunnelAgentNodes []string,
yurttunnelAgentImage string) error {
// 1. Deploy the yurt-tunnel-agent DaemonSet
if err := kubeutil.CreateDaemonSetFromYaml(client,
constants.YurttunnelAgentDaemonSet,
map[string]string{
"image": yurttunnelAgentImage,
"edgeWorkerLabel": projectinfo.GetEdgeWorkerLabelKey()}); err != nil {
return err
}
return nil
}

// prepareClusterInfoConfigMap will create cluster-info configmap in kube-public namespace if it does not exist
func prepareClusterInfoConfigMap(client *kubernetes.Clientset, file string) error {
info, err := client.CoreV1().ConfigMaps(metav1.NamespacePublic).Get(context.Background(), bootstrapapi.ConfigMapClusterInfo, metav1.GetOptions{})
Expand Down
Loading

0 comments on commit da0cd00

Please sign in to comment.