Documentation
¶
Index ¶
- Constants
- Variables
- func BuildClean(deleteNodes, deleteMasters []string)
- func BuildInit()
- func BuildJoin(joinMasters, joinNodes []string)
- func CanUpgradeByNewVersion(new, old string) error
- func CloudInstall(c *Cluster)
- func CmdWork(node, cmd, workdir string) error
- func CmdWorkSpace(node, cmd, workdir string)
- func Cmp(a, b net.IP) int
- func CompressTar(srcDirPath string, destFilePath string) error
- func CompressZip(fileDir string, outputPath string) error
- func Config()
- func Confirm(prompt string) bool
- func DecodeIPs(ips []string) []string
- func DownloadFile(location string) (filePATH, md5 string)
- func Dump(path string, content interface{}) error
- func ExitDeleteCase(pkgUrl string) bool
- func ExitInitCase() bool
- func ExitInstallCase(pkgUrl string) bool
- func ExitUpgradeCase(version, pkgUrl, cfgFile string) error
- func FetchDmosAbsPath() string
- func FileExist(path string) bool
- func For120(version string) bool
- func GetCfg(ep []string) (*clientv3.Config, error)
- func GetConfirmResult(str string) bool
- func GetEtcdClient(ep []string) (*clientv3.Client, error)
- func GetEtcdInitialCluster(hosts []string) string
- func GetEtcdPeerURLs(host string) []string
- func GetMajorMinorInt(version string) (major, minor int)
- func GetRemoteHostName(hostIP string) string
- func IpFormat(host string) string
- func JoinTemplate(ip string, cgroup string) []byte
- func JoinTemplateFromTemplateContent(templateContent, ip, cgroup string) []byte
- func Load(path string, content interface{}) error
- func NewPool(size int) *uPool
- func NextIP(ip net.IP) net.IP
- func ParseIPs(ips []string) []string
- func RandString(len int) string
- func RandStringRunes(n int) string
- func SendPackage(location string, hosts []string, dst string, before, after *string) string
- func SetHosts(hostIP, hostName string)
- func SliceRemoveStr(ss []string, s string) (result []string)
- func Template() []byte
- func TemplateFromTemplateContent(templateContent string) []byte
- func VersionToInt(version string) int
- func VersionToIntAll(version string) int
- type AliOss
- type Apply
- type Check
- type Clean
- type CleanCluster
- type Cluster
- type CommandType
- type DmosClean
- type DmosInstaller
- func (s *DmosInstaller) CheckValid()
- func (s *DmosInstaller) Command(version string, name CommandType) (cmd string)
- func (s *DmosInstaller) CreateKubeconfig()
- func (s *DmosInstaller) GenerateCert()
- func (s *DmosInstaller) GeneratorCerts()
- func (s *DmosInstaller) GeneratorToken()
- func (s *DmosInstaller) InstallMaster0()
- func (s *DmosInstaller) JoinMasters(masters []string)
- func (s *DmosInstaller) JoinNodes()
- func (s *DmosInstaller) KubeadmConfigInstall()
- func (s *DmosInstaller) Print(process ...string)
- func (s *DmosInstaller) PrintFinish()
- func (s *DmosInstaller) SendDmos()
- func (s *DmosInstaller) SendJoinMasterKubeConfigs(masters []string)
- func (s *DmosInstaller) SendKubeConfigs(masters []string)
- func (s *DmosInstaller) SendPackage()
- type DmosUpgrade
- func (u *DmosUpgrade) GetHostNamesFromIps(ips []string) []string
- func (u *DmosUpgrade) GetIpByHostname(host string) string
- func (u *DmosUpgrade) SendPackage()
- func (u *DmosUpgrade) SetIPtoHostName()
- func (u *DmosUpgrade) SetUP()
- func (u *DmosUpgrade) UpgradeMaster0()
- func (u *DmosUpgrade) UpgradeNodes()
- func (u *DmosUpgrade) UpgradeOtherMaster()
- type EtcdFlags
- func (e *EtcdFlags) AfterRestore() error
- func (e *EtcdFlags) CertFileExist() bool
- func (e *EtcdFlags) HealthCheck()
- func (e *EtcdFlags) RecoveryKuBeCluster(dir string)
- func (e *EtcdFlags) RestoreAll()
- func (e *EtcdFlags) Save(inDocker bool) error
- func (e *EtcdFlags) StartPod(dir string)
- func (e *EtcdFlags) StopPod() (string, error)
- type ExecFlag
- type Flags
- type Init
- type Install
- type Join
- type JoinNodeAndMaster
- type KubeadmType
- type PreInit
- type Print
- type RouteFlags
- type SealConfig
- type Send
Constants ¶
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" )
const ( ContainerdShell = `` /* 134-byte string literal not displayed */ DockerShell = `driver=$(docker info -f "{{.CgroupDriver}}") echo "${driver}"` )
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)
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)
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 ¶
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
var ( JoinToken string TokenCaCertHash string CertificateKey string )
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 )
var ClusterDir = "/root/.dmos/clusters/"
var ConfigType string
Functions ¶
func BuildClean ¶
func BuildClean(deleteNodes, deleteMasters []string)
BuildClean clean the build resources.
func CanUpgradeByNewVersion ¶
func CloudInstall ¶
func CloudInstall(c *Cluster)
2019.11.28 今天刚修完陪产假,在新装修的公寓中写代码,刚配的眼镜感觉带着有点不舒服,看屏幕不是很清楚
配眼镜的人也不是很专业,二宝还是个女儿,非常可爱而且非常乖,不像大宝那么吵。 一直很想写日记但是不知道往哪里写合适 既然github要把代码存两千年那为啥不写到代码里,如此这便成为我第一篇代码日记。 碳纤维地暖开了半天还是冰凉的,感觉是被忽悠了。 一写代码就精神万分,一搞管理上的杂事就效率很低,所以做技术还是要专注些。
func CmdWorkSpace ¶
func CmdWorkSpace(node, cmd, workdir string)
CmdWorkSpace exec cmd on specified workdir.
func CompressTar ¶
func CompressZip ¶
CompressZip is compress all file in fileDir , and zip to outputPath like unix zip ./ -r a.zip
func DownloadFile ¶
func ExitDeleteCase ¶
func ExitInstallCase ¶
func ExitUpgradeCase ¶
func GetEtcdInitialCluster ¶
func GetEtcdPeerURLs ¶
func GetRemoteHostName ¶
func JoinTemplate ¶
JoinTemplate is generate JoinCP nodes configuration by master ip.
func RandStringRunes ¶
func SendPackage ¶
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 ¶
Types ¶
type CleanCluster ¶
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
}
type DmosInstaller ¶
type DmosInstaller struct {
Hosts []string
Masters []string
Nodes []string
Network string
ApiServer string
}
DmosInstaller 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) JoinMasters ¶
func (s *DmosInstaller) JoinMasters(masters []string)
JoinMasters is
func (*DmosInstaller) KubeadmConfigInstall ¶
func (s *DmosInstaller) KubeadmConfigInstall()
KubeadmConfigInstall 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
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 GetHealthFlag ¶
func GetRestoreFlags ¶
func (*EtcdFlags) AfterRestore ¶
func (*EtcdFlags) CertFileExist ¶
CertFileExist if cert file is exist return true
func (*EtcdFlags) HealthCheck ¶
func (e *EtcdFlags) HealthCheck()
func (*EtcdFlags) RecoveryKuBeCluster ¶
RecoveryKuBeCluster is when Restore is crashed . do nothing but to recovery
func (*EtcdFlags) RestoreAll ¶
func (e *EtcdFlags) RestoreAll()
RestoreAll is restore all ETCD nodes
type ExecFlag ¶
func GetExecFlag ¶
func (*ExecFlag) IsUseLabeled ¶
IsUseLabeled return true when is labeled
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 JoinNodeAndMaster ¶
type KubeadmType ¶
type RouteFlags ¶
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) ShowDefaultConfig ¶
func (c *SealConfig) ShowDefaultConfig()