install

package
v0.0.0-...-d4fb7ab Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 14, 2021 License: Apache-2.0 Imports: 47 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrorExitOSCase = -1 // 错误直接退出类型

	ErrorMasterEmpty    = "your master is empty."                 // master节点ip为空
	ErrorVersionEmpty   = "your kubernetes version is empty."     // kubernetes 版本号为空
	ErrorFileNotExist   = "your package file is not exist."       // 离线安装包为空
	ErrorPkgUrlNotExist = "Your package url is incorrect."        // 离线安装包为http路径不对
	ErrorPkgUrlSize     = "Download file size is less then 200M " // 离线安装包为http路径不对

	// etcd backup
	ETCDSNAPSHOTDEFAULTNAME = "snapshot"
	ETCDDEFAULTBACKUPDIR    = "/opt/dmos/etcd-backup"
	ETCDDEFAULTRESTOREDIR   = "/opt/dmos/etcd-restore"
	ETCDDATADIR             = "/var/lib/etcd"
	TMPDIR                  = "/tmp"

	// kube file
	KUBECONTROLLERCONFIGFILE = "/etc/kubernetes/controller-manager.conf"
	KUBESCHEDULERCONFIGFILE  = "/etc/kubernetes/scheduler.conf"

	// CriSocket
	DefaultDockerCRISocket     = "/var/run/dockershim.sock"
	DefaultContainerdCRISocket = "/run/containerd/containerd.sock"
	DefaultCgroupDriver        = "cgroupfs"
	DefaultSystemdCgroupDriver = "systemd"
)
View Source
const (
	ContainerdShell = `` /* 134-byte string literal not displayed */

	DockerShell = `driver=$(docker info -f "{{.CgroupDriver}}")
	echo "${driver}"`
)
View Source
const InitTemplateTextV1bate2 = string(`apiVersion: kubeadm.k8s.io/v1beta2
kind: InitConfiguration
localAPIEndpoint:
  advertiseAddress: {{.Master0}}
  bindPort: 6443
nodeRegistration:
  criSocket: /run/containerd/containerd.sock
---
apiVersion: kubeadm.k8s.io/v1beta2
kind: ClusterConfiguration
kubernetesVersion: {{.Version}}
controlPlaneEndpoint: "{{.ApiServer}}:6443"
imageRepository: {{.Repo}}
networking:
  # dnsDomain: cluster.local
  podSubnet: {{.PodCIDR}}
  serviceSubnet: {{.SvcCIDR}}
apiServer:
  certSANs:
  - 127.0.0.1
  - {{.ApiServer}}
  {{range .Masters -}}
  - {{.}}
  {{end -}}
  {{range .CertSANS -}}
  - {{.}}
  {{end -}}
  - {{.VIP}}
  extraArgs:
    feature-gates: TTLAfterFinished=true
  extraVolumes:
  - name: localtime
    hostPath: /etc/localtime
    mountPath: /etc/localtime
    readOnly: true
    pathType: File
controllerManager:
  extraArgs:
    feature-gates: TTLAfterFinished=true
    experimental-cluster-signing-duration: 876000h
{{- if eq .Network "cilium" }}
    allocate-node-cidrs: \"true\"
{{- end }}
  extraVolumes:
  - hostPath: /etc/localtime
    mountPath: /etc/localtime
    name: localtime
    readOnly: true
    pathType: File
scheduler:
  extraArgs:
    feature-gates: TTLAfterFinished=true
  extraVolumes:
  - hostPath: /etc/localtime
    mountPath: /etc/localtime
    name: localtime
    readOnly: true
    pathType: File
---
apiVersion: kubeproxy.config.k8s.io/v1alpha1
kind: KubeProxyConfiguration
mode: "ipvs"
ipvs:
  excludeCIDRs:
  - "{{.VIP}}/32"
---
` + kubeletConfigDefault)
View Source
const InitTemplateTextV1beta1 = string(`apiVersion: kubeadm.k8s.io/v1beta1
kind: InitConfiguration
localAPIEndpoint:
  advertiseAddress: {{.Master0}}
  bindPort: 6443
---
apiVersion: kubeadm.k8s.io/v1beta1
kind: ClusterConfiguration
kubernetesVersion: {{.Version}}
controlPlaneEndpoint: "{{.ApiServer}}:6443"
imageRepository: {{.Repo}}
networking:
  # dnsDomain: cluster.local
  podSubnet: {{.PodCIDR}}
  serviceSubnet: {{.SvcCIDR}}
apiServer:
  certSANs:
  - 127.0.0.1
  - {{.ApiServer}}
  {{range .Masters -}}
  - {{.}}
  {{end -}}
  {{range .CertSANS -}}
  - {{.}}
  {{end -}}
  - {{.VIP}}
  extraArgs:
    feature-gates: TTLAfterFinished=true
  extraVolumes:
  - name: localtime
    hostPath: /etc/localtime
    mountPath: /etc/localtime
    readOnly: true
    pathType: File
controllerManager:
  extraArgs:
    feature-gates: TTLAfterFinished=true
    experimental-cluster-signing-duration: 876000h
{{- if eq .Network "cilium" }}
    allocate-node-cidrs: \"true\"
{{- end }}
  extraVolumes:
  - hostPath: /etc/localtime
    mountPath: /etc/localtime
    name: localtime
    readOnly: true
    pathType: File
scheduler:
  extraArgs:
    feature-gates: TTLAfterFinished=true
  extraVolumes:
  - hostPath: /etc/localtime
    mountPath: /etc/localtime
    name: localtime
    readOnly: true
    pathType: File
---
apiVersion: kubeproxy.config.k8s.io/v1alpha1
kind: KubeProxyConfiguration
mode: "ipvs"
ipvs:
  excludeCIDRs:
  - "{{.VIP}}/32"
---
` + kubeletConfigDefault)
View Source
const JoinCPTemplateTextV1beta2 = string(`apiVersion: kubeadm.k8s.io/v1beta2
caCertPath: /etc/kubernetes/pki/ca.crt
discovery:
  bootstrapToken:
    {{- if .Master}}
    apiServerEndpoint: {{.Master0}}:6443
    {{else}}
    apiServerEndpoint: {{.VIP}}:6443
    {{end -}}
    token: {{.TokenDiscovery}}
    caCertHashes:
    - {{.TokenDiscoveryCAHash}}
  timeout: 5m0s
kind: JoinConfiguration
{{- if .Master }}
controlPlane:
  localAPIEndpoint:
    advertiseAddress: {{.Master}}
    bindPort: 6443
{{- end}}
nodeRegistration:
  criSocket: {{.CriSocket}}
---
` + kubeletConfigDefault)

Variables

View Source
var (
	VersionURL string
	URLMap     map[string]string
	DefaultURL = "https://sealyun.oss-cn-beijing.aliyuncs.com/37374d999dbadb788ef0461844a70151-1.16.0/kube1.16.0.tar.gz"
)

VersionURL is base64 encode k8s version and offline package url

View Source
var (
	JoinToken       string
	TokenCaCertHash string
	CertificateKey  string
)
View Source
var (
	Dst         string
	Src         string
	ExecCommand string
	Label       string
	ExecNode    []string
)
View Source
var (
	MasterIPs []string
	NodeIPs   []string
	CertSANS  []string
	//config from kubeadm.cfg
	DnsDomain         string
	ApiServerCertSANs []string
	//
	SSHConfig sshutil.SSH
	ApiServer string
	//cert abs path
	CertPath     = cert.DmosConfigDir + "/pki"
	CertEtcdPath = cert.DmosConfigDir + "/pki/etcd"
	EtcdCacart   = cert.DmosConfigDir + "/pki/etcd/ca.crt"
	EtcdCert     = cert.DmosConfigDir + "/pki/etcd/healthcheck-client.crt"
	EtcdKey      = cert.DmosConfigDir + "/pki/etcd/healthcheck-client.key"

	//criSocket
	CriSocket    string
	CgroupDriver string

	VIP     string
	PkgUrl  string
	Version string
	Repo    string
	PodCIDR string
	SvcCIDR string

	Envs          []string // read env from -e
	PackageConfig string   // install/delete package config
	Values        string   // values for  install package values.yaml
	WorkDir       string   // workdir for install/delete package home

	//
	Ipvs         care.LvsCare
	LvscareImage ipvs.LvscareImage
	KubeadmFile  string
	// network type, calico or flannel etc..
	Network string
	// if true don't install cni plugin
	WithoutCNI bool
	//network interface name, like "eth.*|en.*"
	Interface string
	// the ipip mode of the calico
	BGP bool
	// mtu size
	MTU string

	YesRx = regexp.MustCompile("^(?i:y(?:es)?)$")

	CleanForce bool
	CleanAll   bool

	Vlog int

	// etcd backup
	InDocker     bool
	SnapshotName string
	EtcdBackDir  string
	RestorePath  string

	// oss
	OssEndpoint      string
	AccessKeyId      string
	AccessKeySecrets string
	BucketName       string
	ObjectPath       string
)
View Source
var ClusterDir = "/root/.dmos/clusters/"
View Source
var ConfigType string

Functions

func BuildClean

func BuildClean(deleteNodes, deleteMasters []string)

BuildClean clean the build resources.

func BuildInit

func BuildInit()

BuildInit is

func BuildJoin

func BuildJoin(joinMasters, joinNodes []string)

BuildJoin is

func CanUpgradeByNewVersion

func CanUpgradeByNewVersion(new, old string) error

func CloudInstall

func CloudInstall(c *Cluster)

2019.11.28 今天刚修完陪产假,在新装修的公寓中写代码,刚配的眼镜感觉带着有点不舒服,看屏幕不是很清楚

配眼镜的人也不是很专业,二宝还是个女儿,非常可爱而且非常乖,不像大宝那么吵。 一直很想写日记但是不知道往哪里写合适
既然github要把代码存两千年那为啥不写到代码里,如此这便成为我第一篇代码日记。

碳纤维地暖开了半天还是冰凉的,感觉是被忽悠了。

一写代码就精神万分,一搞管理上的杂事就效率很低,所以做技术还是要专注些。

func CmdWork

func CmdWork(node, cmd, workdir string) error

func CmdWorkSpace

func CmdWorkSpace(node, cmd, workdir string)

CmdWorkSpace exec cmd on specified workdir.

func Cmp

func Cmp(a, b net.IP) int

Cmp compares two IPs, returning the usual ordering: a < b : -1 a == b : 0 a > b : 1

func CompressTar

func CompressTar(srcDirPath string, destFilePath string) error

func CompressZip

func CompressZip(fileDir string, outputPath string) error

CompressZip is compress all file in fileDir , and zip to outputPath like unix zip ./ -r a.zip

func Config

func Config()

func Confirm

func Confirm(prompt string) bool

send the prompt and get result

func DecodeIPs

func DecodeIPs(ips []string) []string

func DownloadFile

func DownloadFile(location string) (filePATH, md5 string)

func Dump

func Dump(path string, content interface{}) error

func ExitDeleteCase

func ExitDeleteCase(pkgUrl string) bool

func ExitInitCase

func ExitInitCase() bool

ExitOSCase is

func ExitInstallCase

func ExitInstallCase(pkgUrl string) bool

func ExitUpgradeCase

func ExitUpgradeCase(version, pkgUrl, cfgFile string) error

func FetchDmosAbsPath

func FetchDmosAbsPath() string

获取Dmos绝对路径

func FileExist

func FileExist(path string) bool

func For120

func For120(version string) bool

func GetCfg

func GetCfg(ep []string) (*clientv3.Config, error)

func GetConfirmResult

func GetConfirmResult(str string) bool

like y|yes|Y|YES return true

func GetEtcdClient

func GetEtcdClient(ep []string) (*clientv3.Client, error)

func GetEtcdInitialCluster

func GetEtcdInitialCluster(hosts []string) string

func GetEtcdPeerURLs

func GetEtcdPeerURLs(host string) []string

func GetMajorMinorInt

func GetMajorMinorInt(version string) (major, minor int)

GetMajorMinorInt

func GetRemoteHostName

func GetRemoteHostName(hostIP string) string

func IpFormat

func IpFormat(host string) string

IpFormat is

func JoinTemplate

func JoinTemplate(ip string, cgroup string) []byte

JoinTemplate is generate JoinCP nodes configuration by master ip.

func JoinTemplateFromTemplateContent

func JoinTemplateFromTemplateContent(templateContent, ip, cgroup string) []byte

func Load

func Load(path string, content interface{}) error

func NewPool

func NewPool(size int) *uPool

func NextIP

func NextIP(ip net.IP) net.IP

NextIP returns IP incremented by 1

func ParseIPs

func ParseIPs(ips []string) []string

ParseIPs 解析ip 192.168.0.2-192.168.0.6

func RandString

func RandString(len int) string

RandString 生成随机字符串

func RandStringRunes

func RandStringRunes(n int) string

func SendPackage

func SendPackage(location string, hosts []string, dst string, before, after *string) string

location : url md5 dst: /root hook: cd /root && rm -rf kube && tar zxvf %s && cd /root/kube/shell && sh init.sh

func SetHosts

func SetHosts(hostIP, hostName string)

SetHosts set hosts. if can't access to hostName, set /etc/hosts

func SliceRemoveStr

func SliceRemoveStr(ss []string, s string) (result []string)

func Template

func Template() []byte

Template is

func TemplateFromTemplateContent

func TemplateFromTemplateContent(templateContent string) []byte

func VersionToInt

func VersionToInt(version string) int

VersionToInt v1.15.6 => 115

func VersionToIntAll

func VersionToIntAll(version string) int

VersionToIntAll v1.19.1 ==> 1191

Types

type AliOss

type AliOss struct {
	OssEndpoint      string
	AccessKeyId      string
	AccessKeySecrets string
	BucketName       string
	ObjectPath       string
}

type Apply

type Apply interface {
	KubeApply(name string)
}

type Check

type Check interface {
	CheckValid()
}

type Clean

type Clean interface {
	Clean()
}

Clean is

type CleanCluster

type CleanCluster interface {
	Check
	Clean
}

type Cluster

type Cluster struct {
	cloud.Config
	Flags
	Name            string
	Masters         []cloud.VM
	Nodes           []cloud.VM
	VPCID           string
	SwitchID        string
	SecuretyGroupID string
}

Cluster is cluster metadata

var C Cluster

Global config

type CommandType

type CommandType string
const InitMaster CommandType = "initMaster"

command type

const JoinMaster CommandType = "joinMaster"
const JoinNode CommandType = "joinNode"

type DmosClean

type DmosClean struct {
	DmosInstaller
	// contains filtered or unexported fields
}

func (*DmosClean) Clean

func (s *DmosClean) Clean()

Clean clean cluster.

type DmosInstaller

type DmosInstaller struct {
	Hosts     []string
	Masters   []string
	Nodes     []string
	Network   string
	ApiServer string
}

DmosInstaller is

func (*DmosInstaller) CheckValid

func (s *DmosInstaller) CheckValid()

CheckValid is

func (*DmosInstaller) Command

func (s *DmosInstaller) Command(version string, name CommandType) (cmd string)

func (*DmosInstaller) CreateKubeconfig

func (s *DmosInstaller) CreateKubeconfig()

func (*DmosInstaller) GenerateCert

func (s *DmosInstaller) GenerateCert()

func (*DmosInstaller) GeneratorCerts

func (s *DmosInstaller) GeneratorCerts()

GeneratorToken is 这里主要是为了获取CertificateKey

func (*DmosInstaller) GeneratorToken

func (s *DmosInstaller) GeneratorToken()

GeneratorToken is

func (*DmosInstaller) InstallMaster0

func (s *DmosInstaller) InstallMaster0()

InstallMaster0 is

func (*DmosInstaller) JoinMasters

func (s *DmosInstaller) JoinMasters(masters []string)

JoinMasters is

func (*DmosInstaller) JoinNodes

func (s *DmosInstaller) JoinNodes()

JoinNodes is

func (*DmosInstaller) KubeadmConfigInstall

func (s *DmosInstaller) KubeadmConfigInstall()

KubeadmConfigInstall is

func (*DmosInstaller) Print

func (s *DmosInstaller) Print(process ...string)

Print is

func (*DmosInstaller) PrintFinish

func (s *DmosInstaller) PrintFinish()

func (*DmosInstaller) SendDmos

func (s *DmosInstaller) SendDmos()

SendDmos is send the exec Dmos to /usr/bin/Dmos

func (*DmosInstaller) SendJoinMasterKubeConfigs

func (s *DmosInstaller) SendJoinMasterKubeConfigs(masters []string)

func (*DmosInstaller) SendKubeConfigs

func (s *DmosInstaller) SendKubeConfigs(masters []string)

SendKubeConfigs

func (*DmosInstaller) SendPackage

func (s *DmosInstaller) SendPackage()

SendPackage is

type DmosUpgrade

type DmosUpgrade struct {
	SealConfig
	NewVersion   string
	NewPkgUrl    string
	IPtoHostName map[string]string
	Client       *kubernetes.Clientset
}

func NewUpgrade

func NewUpgrade(version, pkgUrl string) *DmosUpgrade

func (*DmosUpgrade) GetHostNamesFromIps

func (u *DmosUpgrade) GetHostNamesFromIps(ips []string) []string

func (*DmosUpgrade) GetIpByHostname

func (u *DmosUpgrade) GetIpByHostname(host string) string

func (*DmosUpgrade) SendPackage

func (u *DmosUpgrade) SendPackage()

SendPackage is send new pkg to all nodes.

func (*DmosUpgrade) SetIPtoHostName

func (u *DmosUpgrade) SetIPtoHostName()

func (*DmosUpgrade) SetUP

func (u *DmosUpgrade) SetUP()

func (*DmosUpgrade) UpgradeMaster0

func (u *DmosUpgrade) UpgradeMaster0()

UpgradeMaster0 is upgrade master first.

func (*DmosUpgrade) UpgradeNodes

func (u *DmosUpgrade) UpgradeNodes()

UpgradeNodes is upgrade nodes.

func (*DmosUpgrade) UpgradeOtherMaster

func (u *DmosUpgrade) UpgradeOtherMaster()

UpgradeOtherMaster is upgrade other master.

type EtcdFlags

type EtcdFlags struct {
	Name       string
	BackDir    string
	EtcdHosts  []string
	Endpoints  []string
	LongName   string
	RestoreDir string
	SealConfig
}

func GetEtcdBackFlags

func GetEtcdBackFlags(cfgFile string) *EtcdFlags

func GetHealthFlag

func GetHealthFlag(cfgFile string) *EtcdFlags

func GetRestoreFlags

func GetRestoreFlags(cfgFile string) *EtcdFlags

func (*EtcdFlags) AfterRestore

func (e *EtcdFlags) AfterRestore() error

func (*EtcdFlags) CertFileExist

func (e *EtcdFlags) CertFileExist() bool

CertFileExist if cert file is exist return true

func (*EtcdFlags) HealthCheck

func (e *EtcdFlags) HealthCheck()

func (*EtcdFlags) RecoveryKuBeCluster

func (e *EtcdFlags) RecoveryKuBeCluster(dir string)

RecoveryKuBeCluster is when Restore is crashed . do nothing but to recovery

func (*EtcdFlags) RestoreAll

func (e *EtcdFlags) RestoreAll()

RestoreAll is restore all ETCD nodes

func (*EtcdFlags) Save

func (e *EtcdFlags) Save(inDocker bool) error

func (*EtcdFlags) StartPod

func (e *EtcdFlags) StartPod(dir string)

todo

func (*EtcdFlags) StopPod

func (e *EtcdFlags) StopPod() (string, error)

StopPod is stop kubernetes kube-apiserver kube-controller-manager kube-scheduler etcd by mv dir to other location.

type ExecFlag

type ExecFlag struct {
	Dst      string
	Src      string
	Cmd      string
	Label    string
	ExecNode []string
	SealConfig
}

func GetExecFlag

func GetExecFlag(cfgFile string) *ExecFlag

func (*ExecFlag) Copy

func (e *ExecFlag) Copy()

Copy is cp src file to dst file

func (*ExecFlag) Exec

func (e *ExecFlag) Exec()

Exec is cp src file to dst file

func (*ExecFlag) IsUseCmd

func (e *ExecFlag) IsUseCmd() bool

IsUseCmd return true when you want to exec cmd

func (*ExecFlag) IsUseCopy

func (e *ExecFlag) IsUseCopy() bool

IsUseCopy return true when you want to copy file

func (*ExecFlag) IsUseLabeled

func (e *ExecFlag) IsUseLabeled() bool

IsUseLabeled return true when is labeled

func (*ExecFlag) IsUseNode

func (e *ExecFlag) IsUseNode() bool

IsUseNode return true when is use --node

type Flags

type Flags struct {
	Master      int
	MasterType  string
	Node        int
	NodeType    string
	Version     string
	Flavor      string
	Passwd      string
	Zone        string
	Interaction bool
	Image       string
}

Flags is command line paras

type Init

type Init interface {
	Check
	Send
	PreInit
	Join
	Print
}

type Install

type Install interface {
	Check
	Send
	Apply
}

type Join

type Join interface {
	JoinMasters()
	JoinNodes()
	GeneratorToken()
}

Join is

type JoinNodeAndMaster

type JoinNodeAndMaster interface {
	Check
	Send
	Join
}

type KubeadmType

type KubeadmType struct {
	Kind      string `yaml:"kind,omitempty"`
	ApiServer struct {
		CertSANs []string `yaml:"certSANs,omitempty"`
	} `yaml:"apiServer"`
	Networking struct {
		DnsDomain string `yaml:"dnsDomain,omitempty"`
	} `yaml:"networking"`
}

func KubeadmDataFromYaml

func KubeadmDataFromYaml(context string) *KubeadmType

根据yaml转换kubeadm结构

type PreInit

type PreInit interface {
	KubeadmConfigInstall()
	InstallMaster0()
}

PreInit is

type Print

type Print interface {
	Print(process ...string)
}

Print is

type RouteFlags

type RouteFlags struct {
	Host    string
	Gateway string
}

func GetRouteFlag

func GetRouteFlag(host, gateway string) *RouteFlags

func (*RouteFlags) CheckRoute

func (r *RouteFlags) CheckRoute()

func (*RouteFlags) DelRoute

func (r *RouteFlags) DelRoute()

func (*RouteFlags) SetRoute

func (r *RouteFlags) SetRoute()

type SealConfig

type SealConfig struct {
	Masters []string
	Nodes   []string
	//config from kubeadm.cfg. ex. cluster.local
	DnsDomain         string
	ApiServerCertSANs []string

	//SSHConfig
	User       string
	Passwd     string
	PrivateKey string
	PkPassword string
	//ApiServer ex. apiserver.cluster.local
	ApiServerDomain string
	Network         string
	VIP             string
	PkgURL          string
	Version         string
	Repo            string
	PodCIDR         string
	SvcCIDR         string
	//certs location
	CertPath     string
	CertEtcdPath string
	//lvscare images
	LvscareName string
	LvscareTag  string
	AliOss
}

SealConfig for ~/.dmos/config.yaml

func (*SealConfig) Dump

func (c *SealConfig) Dump(path string)

Dump is

func (*SealConfig) Load

func (c *SealConfig) Load(path string) (err error)

Load is

func (*SealConfig) ShowDefaultConfig

func (c *SealConfig) ShowDefaultConfig()

type Send

type Send interface {
	SendPackage()
}

Send is

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL