Documentation
¶
Index ¶
- Constants
- Variables
- func CheckImageExists(host string, username string, password string, imageName string, tag string) bool
- func CheckPodName(namespace string, serviceName string, clientSet kubernetes.Clientset, ...) bool
- func CheckQuota(username string, podNumber int64, cpu int64, memory int64, resourceName string) (bool, string)
- func ClearJob(clientSet kubernetes.Clientset)
- func CreateConfigmap(param ServiceParam)
- func CreateDeamonSet(param ServiceParam)
- func CreateFilebeatConfig(param ServiceParam) map[string]interface{}
- func CreateGlusterfs(param StorageParam)
- func CreateImagePullSecret(param ServiceParam)
- func CreateJob(param JobParam) string
- func CreateNfsStorageServer(param StorageParam)
- func CreateNginxConf(confType string)
- func CreateNginxLb(param ServiceParam)
- func CreateRegistry(param RegistryParam) error
- func CreateService()
- func CreateServiceAccount(client kubernetes.Clientset, namespace string, name string)
- func CreateServicePod(param ServiceParam) (string, error)
- func CreateServicePvc(param ServiceParam, pvcName string, containerPath string) error
- func DeleteJob(clientSet kubernetes.Clientset, jobName string, namespace string)
- func DeletePod(namespace string, name string, clientSet kubernetes.Clientset) error
- func DeletePvc(param StorageParam) error
- func DeleteRegistryImage(host string, username string, password string, imageName string, tag string) (bool, error)
- func DeleteSecret(client kubernetes.Clientset, namespace string)
- func DeleteService(clustername string, namespace string, name string) error
- func DeletelDeployment(namespace string, isService bool, name string, clusterName string) error
- func Exec(clustername string, podname string, namespace string, containername string, ...) string
- func GetAppService(clientset kubernetes.Clientset, namespace string, serviceName string) *v1.Service
- func GetAutoScale(clustername string, namespace string, name string) (v2beta1.HorizontalPodAutoscaler, error)
- func GetCertConfigData(keyFile string, sslDbName map[string]interface{}) map[string]interface{}
- func GetClient(cluster string) (kubernetes.Clientset, error)
- func GetClusterStatus(clusterName string) string
- func GetContainerStatus(namespace string, clientSet kubernetes.Clientset) []app.CloudContainer
- func GetCurrentPort(clientset kubernetes.Clientset, namespace string, name string) util.Lock
- func GetCusomService(clientset kubernetes.Clientset, namespace string) []string
- func GetDeployment(namespace string, clientset kubernetes.Clientset, name string) v1beta12.Deployment
- func GetDeploymentApp(clientSet kubernetes.Clientset, namespace string, service string) map[string]CloudApp
- func GetDeploymentStatus(namespace string, name string, client kubernetes.Clientset) (bool, string)
- func GetDeployments(namespace string, clientset kubernetes.Clientset) []v1beta12.Deployment
- func GetDeploymentsService(namespace string, clientset kubernetes.Clientset, service string) []v1beta12.Deployment
- func GetDeploymentsVersion(namespace string, name string, client kubernetes.Clientset) string
- func GetDockerImagePullName(name string) string
- func GetIpPodNumber(pods []v1.Pod, ip string) int
- func GetJobLogs(cl kubernetes.Clientset, pod string, namespace string, line int64) string
- func GetLastCountData(param QueryParam) float64
- func GetLbDataSearchMap(searchMap sql.SearchMap) interface{}
- func GetMasterIp(cluster string) (string, string)
- func GetNamespaces(clientset kubernetes.Clientset) ([]v1.Namespace, error)
- func GetNodes(clientset kubernetes.Clientset, labels string) []v1.Node
- func GetPods(namespace string, clientSet kubernetes.Clientset) []v1.Pod
- func GetPodsFromNode(node string, clientSet kubernetes.Clientset) v1.PodList
- func GetPodsNumber(namespace string, clientSet kubernetes.Clientset) int
- func GetPodsService(namespace string, serviceName string, clientSet kubernetes.Clientset) []v1.Pod
- func GetRegistryInfo(host string, username string, password string, registryName string) (util.Lock, util.Lock, util.Lock)
- func GetRestlient(cluster string) (*rest.RESTClient, restclient.Config, error)
- func GetServerPort(clientset kubernetes.Clientset, namespace string, name string) util.Lock
- func GetServiceAccount(name string, param StorageParam) string
- func GetServiceFreePort(clientset kubernetes.Clientset) int32
- func GetServiceNumber(clientset kubernetes.Clientset, namespace string) int
- func GetServicePort(clientset kubernetes.Clientset, namespace string, name string) *v1.Service
- func GetServicePorts(clientset kubernetes.Clientset, size int, start int, end int) []int
- func GetServiceUsedPort(clientset kubernetes.Clientset) []int
- func GetServices(clientset kubernetes.Clientset, namespace string) ([]v1.Service, error)
- func GetYamlClient(cluster string, groups string, version string, api string) (*dynamic.Client, error)
- func ImageCommit(clusterName string, imagePushParam ImagePushParam, baseImage string)
- func ImagePush(clusterName string, imagePushParam ImagePushParam)
- func IsHugePageResourceName(name v1.ResourceName) bool
- func IsStandardContainerResourceName(str string) bool
- func MakeTestJob(master string, port string, clusterName string) (string, int64)
- func MakeTestNginxConfMap(confdata map[string]interface{}, sslData map[string]interface{}, ...)
- func ParseMonitorData(param QueryParam)
- func PodRequestsAndLimits(pod *v1.Pod) (reqs v1.ResourceList, limits v1.ResourceList)
- func Query(param QueryParam) string
- func ScalePod(clustername string, namespace string, name string, replicas int32) error
- func SecretIsExists(client kubernetes.Clientset, namespace string, name string) bool
- func SetLimts(clustername string, namespace string, mem string, cpu interface{}, ...) error
- func UpdateDeploymentImage(param RollingParam) (bool, error)
- func UpdateGlusterfsTopology(clustername string, client kubernetes.Clientset)
- func UpdateNginxLbUpstream(param UpdateLbNginxUpstream) error
- func UpdateNodeLabels(clustername string, ip string, labelsData string) error
- func UpdateNodeStatus(client kubernetes.Clientset, ip string, unschdulable bool) error
- func WriteMountDataToDb(configname string, dataName string, cluster string, namespace string, ...)
- func YamlCreateNamespace(clustername string, namespace string) error
- func YamlCreateService(appname string, resourceName string, containerPort int32, cl *dynamic.Client, ...) error
- func YamlDaemonSet(master string, port string, yaml []byte, namespace string)
- func YamlDeployment(clustername string, yaml []byte, namespace string, isService bool, uuid string) error
- func YamlLbHaproxy()
- func YamlLbNgxin()
- func YamlStatefulSets(master string, port string, yaml []byte, namespace string)
- type Affinity
- type AppPodStatus
- type AutoScaleParam
- type CertData
- type CloudApp
- type CloudAutoScaleLog
- type CloudClusterHosts
- type CloudConfigureMount
- type CloudImage
- type CloudImageSyncLog
- type CloudLb
- type CloudLbCert
- type CloudLbNginxConf
- type CloudLbService
- type CloudStorage
- type CloudStorageMountInfo
- type ClusterHealth
- type ClusterResources
- type ClusterStatus
- type ConfigureData
- type EventData
- type HealthData
- type HostImages
- type ImagePushParam
- type JobParam
- type NodeIp
- type NodeReport
- type NodeSelector
- type NodeStatus
- type PortData
- type QueryParam
- type RegistryLock
- type RegistryParam
- type RollingParam
- type ServiceParam
- type ServicePod
- type StorageData
- type StorageParam
- type UpdateLbNginxUpstream
Constants ¶
const ( InsertCloudLbNginxConf = "insert into cloud_lb_nginx_conf" SelectCloudLbNginxConf = "" /* 194-byte string literal not displayed */ SelectCloudLbCert = "" /* 133-byte string literal not displayed */ SelectCloudLbService = "" /* 313-byte string literal not displayed */ )
const ( NginxUpstreamPath = "/usr/local/nginx/conf/vhosts/upstream" NginxConfigPath = "/usr/local/nginx/conf/vhosts/conf" NginxSslPath = "/usr/local/nginx/conf/vhosts/ssl" LbNginxConfig = "lb-nginx-config" LbNginxUpstream = "lb-nginx-upstream" LbNginxSsl = "lb-nginx-ssl" LbNginxStartPath = "/start/" LbNginxDaemonPath = "/daemon/" )
nginx配置文件路径
const DeleteCloudConfigureMount = "delete from cloud_configure_mount"
const InsertCloudAutoScaleLog = "insert into cloud_auto_scale_log"
2018-02-20 17:10 记录扩容操作日志
const InsertCloudConfigureMount = "insert into cloud_configure_mount"
const InsertCloudImageSyncLog = "insert into cloud_image_sync_log"
2018-02-06 10:45 镜像提交完成后写入日志
const NodeLost = "NodeLost"
const SelectCloudClusterHosts = "select host_ip,host_type,cluster_name,api_port from cloud_cluster_hosts"
const SelectCloudConfigureMount = "" /* 143-byte string literal not displayed */
const SelectCloudLb = "" /* 234-byte string literal not displayed */
const SelectServiceReplicas = `` /* 170-byte string literal not displayed */
const UpdateCloudConfigureMount = "update cloud_configure_mount"
const UpdateCloudImageSyncLog = "update cloud_image_sync_log"
Variables ¶
var ( StartCmd = `` /* 141-byte string literal not displayed */ RegistryTemplate = `` /* 528-byte string literal not displayed */ )
var HubLockCache = RegistryLock{}
var LEVEL_0 = 0
var LEVEL_1 = 1
var NGINX_NODES = util.Lock{}
Functions ¶
func CheckImageExists ¶
func CheckImageExists(host string, username string, password string, imageName string, tag string) bool
2018-02-09 17:01 检查镜像是否存在
func CheckPodName ¶
func CheckPodName(namespace string, serviceName string, clientSet kubernetes.Clientset, name string) bool
2018/10/11 11:00:30 检查名称是否在pod中
func CheckQuota ¶
func CheckQuota(username string, podNumber int64, cpu int64, memory int64, resourceName string) (bool, string)
2018-02-11 21:59 检查配置服务时配额是否够用 检查资源配额是否够用
func CreateConfigmap ¶
func CreateConfigmap(param ServiceParam)
创建配置文件 @param name 2018-01-17 16:18 data := app.GetConfgData("adf","asdfasdfdasf") k8s.CreateConfigmap("10.16.55.6","8080",data, "adf","test-app--dfsad")
func CreateGlusterfs ¶
func CreateGlusterfs(param StorageParam)
2018-02-21 15:03 需要物理硬件支持,每个机器有一块单独的硬盘 创建glusterfs集群 节点需要添加标签 storagenode=glusterfs
func CreateImagePullSecret ¶
func CreateImagePullSecret(param ServiceParam)
2018-02-04 20:51 为私有镜像仓库拉取镜像添加拉取权限
func CreateNfsStorageServer ¶
func CreateNfsStorageServer(param StorageParam)
name example-nfs accessModes ReadWriteMany
func CreateService ¶
func CreateService()
func CreateServiceAccount ¶
func CreateServiceAccount(client kubernetes.Clientset, namespace string, name string)
2018-02-11 创建默认serviceAccount
func CreateServicePod ¶
func CreateServicePod(param ServiceParam) (string, error)
创建服务 c1,_ := k8s.GetYamlClient("10.16.55.6","8080","apps","v1beta1","/apis") storageData := `[{"ContainerPath":"/tmp/mnt","HostPath":"/mnt","Volume":""},{"Volume":"","ContainerPath":"/tmp","HostPath":"/mnt"}]` lables := `{"Value":"10.16.55.102","Lables":"kubernetes.io/hostname"}` affinityData := `[{"Type":"zone","Value":"node103"}]` k8s.CreateServicePod(c1,"default","test1",0.1,"1024","80",storageData,"nginx:1.11",affinityData, lables) 2018-01-11 15:02 c1,_ := k8s.GetYamlClient("10.16.55.6","8080","apps","v1beta1","/apis")
func CreateServicePvc ¶
func CreateServicePvc(param ServiceParam, pvcName string, containerPath string) error
2018-01-30 21:07 创建pvc
func DeleteJob ¶
func DeleteJob(clientSet kubernetes.Clientset, jobName string, namespace string)
构建完成后删除job 2018-01-26 16:34
func DeletePod ¶
func DeletePod(namespace string, name string, clientSet kubernetes.Clientset) error
2018-01-16 12:25 删除某个pod后自动重建
func DeleteRegistryImage ¶
func DeleteRegistryImage(host string, username string, password string, imageName string, tag string) (bool, error)
2018-01-29 8:27 删除镜像
func DeleteSecret ¶
func DeleteSecret(client kubernetes.Clientset, namespace string)
2018-02-09 15:22 删除secret
func DeleteService ¶
删除某个service
func DeletelDeployment ¶
删除 deployment
func Exec ¶
func Exec(clustername string, podname string, namespace string, containername string, cmd []string) string
2018-02-27 17:35 执行命令
func GetAppService ¶
func GetAppService(clientset kubernetes.Clientset, namespace string, serviceName string) *v1.Service
2018-02-13 19:27 获取服务信息
func GetAutoScale ¶
func GetAutoScale(clustername string, namespace string, name string) (v2beta1.HorizontalPodAutoscaler, error)
2018-01-13 17:54 获取扩展信息 {"metadata":{"name":"auto-3","namespace":"auto-3--dfsad","selfLink":"/apis/autoscaling/v2beta1/namespaces/auto-3--dfsad/horizontalpodautoscalers/auto-3","uid":"3a4ec944-f83e-11e7-8d1c-0894ef37b2d2","resourceVersion":"4149862","creationTimestamp":"2018-01-13T08:46:20Z"},"spec":{"scaleTargetRef":{"kind":"Deployment","name":"auto-3","apiVersion":"extensions/v1beta1"},"minReplicas":1,"maxReplicas":2,"metrics":[{"type":"Resource","resource":{"name":"cpu","targetAverageUtilization":80}}]},"status":{"lastScaleTime":"2018-01-13T09:45:51Z","currentReplicas":2,"desiredReplicas":2,"currentMetrics":null,"conditions":[{"type":"AbleToScale","status":"True","lastTransitionTime":"2018-01-13T08:46:50Z","reason":"SucceededGetScale","message":"the HPA controller was able to get the target's current scale"},{"type":"ScalingActive","status":"False","lastTransitionTime":"2018-01-13T08:46:50Z","reason":"FailedGetResourceMetric","message":"the HPA was unable to compute the replica count: unable to get metrics for resource cpu: failed to get pod resource metrics: the server could not find the requested resource (get services http:heapster:)"}]}} <nil>
func GetCertConfigData ¶
2108-02-03 11:30 获取虚拟主机证书文件
func GetClusterStatus ¶
2018-02-28 11:16 每次读取 获取集群组件监控状态
func GetContainerStatus ¶
func GetContainerStatus(namespace string, clientSet kubernetes.Clientset) []app.CloudContainer
{"name":"auto-service","image":"nginx:1.10","ports":[{"containerPort":80,"protocol":"TCP"}],"resources":{"limits":{"cpu":"1","memory":"2Gi"},"requests":{"cpu":"1","memory":"2Gi"}},"terminationMessagePath":"/dev/termination-log","terminationMessagePolicy":"File","imagePullPolicy":"IfNotPresent"} 获取某个namespace下面的服务
func GetCurrentPort ¶
2018-01-14 17:52 获取当前服务使用的端口,和集群地址 在更新service的时候使用
func GetCusomService ¶
func GetCusomService(clientset kubernetes.Clientset, namespace string) []string
获取自定义的namespace的service
func GetDeployment ¶
func GetDeployment(namespace string, clientset kubernetes.Clientset, name string) v1beta12.Deployment
2018-02-19 15:08 获取Deployment信息
func GetDeploymentApp ¶
func GetDeploymentApp(clientSet kubernetes.Clientset, namespace string, service string) map[string]CloudApp
svc {"metadata":{"name":"auto-nginx-3","namespace":"auto-nginx-3--dfsad","selfLink":"/api/v1/namespaces/auto-nginx-3--dfsad/services/auto-nginx-3","uid":"2c62631d-f773-11e7-8d1c-0894ef37b2d2","resourceVersion":"4030027","creationTimestamp":"2018-01-12T08:32:49Z","labels":{"app":"auto-nginx-3"}},"spec":{"ports":[{"name":"auto-nginx-3-0","protocol":"TCP","port":49873,"targetPort":80,"nodePort":49873}],"selector":{"name":"auto-nginx-3"},"clusterIP":"172.16.1.62","type":"NodePort","sessionAffinity":"None","externalTrafficPolicy":"Cluster"},"status":{"loadBalancer":{}}} deploy {"metadata":{"name":"auto-3","namespace":"auto-3--dfsad","selfLink":"/apis/apps/v1beta1/namespaces/auto-3--dfsad/deployments/auto-3","uid":"ee1a2658-f780-11e7-8d1c-0894ef37b2d2","resourceVersion":"4037873","generation":1,"creationTimestamp":"2018-01-12T10:11:18Z","labels":{"name":"auto-3"},"annotations":{"deployment.kubernetes.io/revision":"1"}},"spec":{"replicas":1,"selector":{"matchLabels":{"name":"auto-3"}},"template":{"metadata":{"creationTimestamp":null,"labels":{"name":"auto-3"}},"spec":{"containers":[{"name":"auto-3","image":"nginx:1.10","ports":[{"containerPort":80,"protocol":"TCP"}],"resources":{"limits":{"cpu":"1","memory":"2Gi"},"requests":{"cpu":"1","memory":"2Gi"}},"terminationMessagePath":"/dev/termination-log","terminationMessagePolicy":"File","imagePullPolicy":"IfNotPresent"}],"restartPolicy":"Always","terminationGracePeriodSeconds":30,"dnsPolicy":"ClusterFirst","securityContext":{},"schedulerName":"default-scheduler"}},"strategy":{"type":"RollingUpdate","rollingUpdate":{"maxUnavailable":"25%","maxSurge":"25%"}},"revisionHistoryLimit":2,"progressDeadlineSeconds":600},"status":{"observedGeneration":1,"replicas":1,"updatedReplicas":1,"readyReplicas":1,"availableReplicas":1,"conditions":[{"type":"Available","status":"True","lastUpdateTime":"2018-01-12T10:11:20Z","lastTransitionTime":"2018-01-12T10:11:20Z","reason":"MinimumReplicasAvailable","message":"Deployment has minimum availability."},{"type":"Progressing","status":"True","lastUpdateTime":"2018-01-12T10:11:20Z","lastTransitionTime":"2018-01-12T10:11:18Z","reason":"NewReplicaSetAvailable","message":"ReplicaSet \"auto-3-8548fd9d57\" has successfully progressed."}]}} 获取自己创建的namespace应用, 规则是app名加资源名区分
func GetDeploymentStatus ¶
2018-02-04 18:14 获取是否可以更新deployment
func GetDeployments ¶
func GetDeployments(namespace string, clientset kubernetes.Clientset) []v1beta12.Deployment
获某个namespace下面的deployment信息 {"metadata":{"name":"deploymentexample","namespace":"testservice--asdfasdfdasf","selfLink":"/apis/apps/v1beta1/namespaces/testservice--asdfasdfdasf/deployments/deploymentexample","uid":"c30cd8ea-f34e-11e7-8d1c-0894ef37b2d2","resourceVersion":"3433025","generation":1,"creationTimestamp":"2018-01-07T02:02:06Z","labels":{"release-version":"0","space":"testservice--asdfasdfdasf","uuid":"7e22a9b7fc32748be8527f6e2592ea67","zcloud-app":"testservice--asdfasdfdasf"},"annotations":{"deployment.kubernetes.io/revision":"1"}},"spec":{"replicas":3,"selector":{"matchLabels":{"app":"nginx"}},"template":{"metadata":{"creationTimestamp":null,"labels":{"app":"nginx"}},"spec":{"containers":[{"name":"nginx","image":"nginx:1.10","ports":[{"containerPort":80,"protocol":"TCP"}],"resources":{},"terminationMessagePath":"/dev/termination-log","terminationMessagePolicy":"File","imagePullPolicy":"IfNotPresent"}],"restartPolicy":"Always","terminationGracePeriodSeconds":30,"dnsPolicy":"ClusterFirst","securityContext":{},"schedulerName":"default-scheduler"}},"strategy":{"type":"RollingUpdate","rollingUpdate":{"maxUnavailable":"25%","maxSurge":"25%"}},"revisionHistoryLimit":2,"progressDeadlineSeconds":600},"status":{"observedGeneration":1,"replicas":3,"updatedReplicas":3,"readyReplicas":3,"availableReplicas":3,"conditions":[{"type":"Available","status":"True","lastUpdateTime":"2018-01-07T02:02:09Z","lastTransitionTime":"2018-01-07T02:02:09Z","reason":"MinimumReplicasAvailable","message":"Deployment has minimum availability."},{"type":"Progressing","status":"True","lastUpdateTime":"2018-01-07T02:02:09Z","lastTransitionTime":"2018-01-07T02:02:06Z","reason":"NewReplicaSetAvailable","message":"ReplicaSet \"deploymentexample-845cfc7fb9\" has successfully progressed."}]}}
func GetDeploymentsService ¶
func GetDeploymentsService(namespace string, clientset kubernetes.Clientset, service string) []v1beta12.Deployment
获取某个服务的信息 2018-01-18 10:02
func GetDeploymentsVersion ¶
func GetDeploymentsVersion(namespace string, name string, client kubernetes.Clientset) string
2018-02-04 17:36 获取deploy更新前版本
func GetJobLogs ¶
func GetLbDataSearchMap ¶
2018-08-17 08:25 搜索l信息
func GetMasterIp ¶
func GetNamespaces ¶
func GetNamespaces(clientset kubernetes.Clientset) ([]v1.Namespace, error)
获取namespace
func GetPods ¶
func GetPods(namespace string, clientSet kubernetes.Clientset) []v1.Pod
获取pod数据 fmt.Println(p.Status.HostIP) {"metadata":{"name":"zhaoyun1-rc-28fp6","generateName":"zhaoyun1-rc-","namespace":"default","selfLink":"/api/v1/namespaces/default/pods/zhaoyun1-rc-28fp6","uid":"29676a19-dbbd-11e7-a7e2-0894ef37b2d2","resourceVersion":"287211","creationTimestamp":"2017-12-08T02:11:54Z","labels":{"app":"www-gg-com","max-scale":"3","min-scale":"3"},"annotations":{"kubernetes.io/created-by":"{\"kind\":\"SerializedReference\",\"apiVersion\":\"v1\",\"reference\":{\"kind\":\"ReplicationController\",\"namespace\":\"default\",\"name\":\"zhaoyun1-rc\",\"uid\":\"2966d58b-dbbd-11e7-a7e2-0894ef37b2d2\",\"apiVersion\":\"v1\",\"resourceVersion\":\"287184\"}}\n"},"ownerReferences":[{"apiVersion":"v1","kind":"ReplicationController","name":"zhaoyun1-rc","uid":"2966d58b-dbbd-11e7-a7e2-0894ef37b2d2","controller":true,"blockOwnerDeletion":true}]},"spec":{"containers":[{"name":"zhaoyun1","image":"nginx:1.11","ports":[{"containerPort":80,"protocol":"TCP"}],"resources":{"limits":{"cpu":"1","memory":"0"},"requests":{"cpu":"1","memory":"0"}},"terminationMessagePath":"/dev/termination-log","terminationMessagePolicy":"File","imagePullPolicy":"IfNotPresent"}],"restartPolicy":"Always","terminationGracePeriodSeconds":30,"dnsPolicy":"ClusterFirst","nodeName":"10.16.55.103","securityContext":{},"schedulerName":"default-scheduler"},"status":{"phase":"Running","conditions":[{"type":"Initialized","status":"True","lastProbeTime":null,"lastTransitionTime":"2017-12-08T02:10:19Z"},{"type":"Ready","status":"True","lastProbeTime":null,"lastTransitionTime":"2017-12-08T02:10:23Z"},{"type":"PodScheduled","status":"True","lastProbeTime":null,"lastTransitionTime":"2017-12-08T02:11:54Z"}],"hostIP":"10.16.55.103","podIP":"172.16.8.15","startTime":"2017-12-08T02:10:19Z","containerStatuses":[{"name":"zhaoyun1","state":{"running":{"startedAt":"2017-12-08T02:10:22Z"}},"lastState":{},"ready":true,"restartCount":0,"image":"nginx:1.11","imageID":"docker-pullable://nginx@sha256:e6693c20186f837fc393390135d8a598a96a833917917789d63766cab6c59582","containerID":"docker://c0a1cae85d6146d415996252750add084373c0f0e90c68fb129e3aa440262645"}],"qosClass":"Burstable"}}
func GetPodsFromNode ¶
func GetPodsFromNode(node string, clientSet kubernetes.Clientset) v1.PodList
2018-09-04 08:59 获取某个节点的数据
func GetPodsNumber ¶
func GetPodsNumber(namespace string, clientSet kubernetes.Clientset) int
获取pods数量
func GetPodsService ¶
func GetPodsService(namespace string, serviceName string, clientSet kubernetes.Clientset) []v1.Pod
获取某个服务的pods @param namespace @param serviceName 2018-01-18 9:53
func GetRegistryInfo ¶
func GetRegistryInfo(host string, username string, password string, registryName string) (util.Lock, util.Lock, util.Lock)
2018-01-27 21:06 获取仓库中不同组的镜像数量和tag数量
func GetRestlient ¶
func GetRestlient(cluster string) (*rest.RESTClient, restclient.Config, error)
2018-02-28 09:26 获取用来执行命令和websocke使用的client
func GetServerPort ¶
2018-02-20 11:29 获取服务端口
func GetServiceAccount ¶
func GetServiceAccount(name string, param StorageParam) string
2018-01-30 17:37 获取serviceaccount信息
func GetServiceFreePort ¶
func GetServiceFreePort(clientset kubernetes.Clientset) int32
获取一个端口给service使用 获取最大不超过65535
func GetServiceNumber ¶
func GetServiceNumber(clientset kubernetes.Clientset, namespace string) int
获取某个集群服务的数量
func GetServicePort ¶
func GetServicePort(clientset kubernetes.Clientset, namespace string, name string) *v1.Service
获取某个服务使用的端口 2018-01-21 18:03
func GetServicePorts ¶
获取可用的端口,一次获取多个 2018-01-14 14:29
func GetServiceUsedPort ¶
func GetServiceUsedPort(clientset kubernetes.Clientset) []int
获取k8s svc 已经使用的端口 应该任务计划去执行,数据放到库里 端口范围默认Wie
func GetServices ¶
func GetServices(clientset kubernetes.Clientset, namespace string) ([]v1.Service, error)
获取某个集群的服务信息
func GetYamlClient ¶
func GetYamlClient(cluster string, groups string, version string, api string) (*dynamic.Client, error)
通过yaml方式部署服务
func ImageCommit ¶
func ImageCommit(clusterName string, imagePushParam ImagePushParam, baseImage string)
2018-08-21 14:36 容器保存为镜像
func ImagePush ¶
func ImagePush(clusterName string, imagePushParam ImagePushParam)
将A的镜像推送到B集群去 镜像推送服务
func IsHugePageResourceName ¶
func IsHugePageResourceName(name v1.ResourceName) bool
IsHugePageResourceName returns true if the resource name has the huge page resource prefix.
func IsStandardContainerResourceName ¶
IsStandardContainerResourceName returns true if the container can make a resource request for the specified resource
func MakeTestJob ¶
创建测试任务,检查nginx配置文件 2018-02-02 20:30
func MakeTestNginxConfMap ¶
func MakeTestNginxConfMap(confdata map[string]interface{}, sslData map[string]interface{}, clusterName string)
2018-02-03 07:51 创建用于测试的nginx配置
func PodRequestsAndLimits ¶
func PodRequestsAndLimits(pod *v1.Pod) (reqs v1.ResourceList, limits v1.ResourceList)
PodRequestsAndLimits returns a dictionary of all defined resources summed up for all containers of the pod.
func ScalePod ¶
2018-01-13 10:32 将应用扩展或停止 k8s.ScalePod("10.16.55.6","8080","auto-3--dfsad","auto-3",4)
func SecretIsExists ¶
func SecretIsExists(client kubernetes.Clientset, namespace string, name string) bool
2018-02-04 21:32 获取安全密码是否存在
func SetLimts ¶
func SetLimts(clustername string, namespace string, mem string, cpu interface{}, action string) error
设置默认资源使用
func UpdateDeploymentImage ¶
func UpdateDeploymentImage(param RollingParam) (bool, error)
2018-02-04 19:55 更新镜像
func UpdateGlusterfsTopology ¶
func UpdateGlusterfsTopology(clustername string, client kubernetes.Clientset)
2018-02-21 16:12 更新glusterfs集群信息
func UpdateNginxLbUpstream ¶
func UpdateNginxLbUpstream(param UpdateLbNginxUpstream) error
2018-02-17 21:10 更新nginx的upstream
func UpdateNodeLabels ¶
更新某个node的标签 2018-01-11 18:00 k8s.UpdateNodeLabels("10.16.55.6","8080","10.16.55.102","sshd","sshd","")
func UpdateNodeStatus ¶
func UpdateNodeStatus(client kubernetes.Clientset, ip string, unschdulable bool) error
设置节点是否可调度
func WriteMountDataToDb ¶
func WriteMountDataToDb(configname string, dataName string, cluster string, namespace string, mountpath string, serviceName string)
2018-01-18 11:31 将挂载数据写入到数据
func YamlCreateNamespace ¶
创建namespace
func YamlCreateService ¶
func YamlCreateService(appname string, resourceName string, containerPort int32, cl *dynamic.Client, nodePort int32, selector map[string]string, namespace string) error
--service-node-port-range=20000-65535 NodePort 对外部可见的 创建一个service, 在应用创建完成后,自动创建一个service 通过配置开关来定义是否创建service,如果打开就创建,主要用于http非服务化的服务 c,_ := k8s.GetYamlClient("10.16.55.6","8080", "","v1", "api") b := k8s.YamlCreateService("my-nginx","dddd",80, c, 50000, "cccccc")
uuid 为创建pods时候生成的
func YamlDaemonSet ¶
通过yaml创建DaemonSet服务
func YamlDeployment ¶
func YamlDeployment(clustername string, yaml []byte, namespace string, isService bool, uuid string) error
apiVersion: apps/v1beta1 kind: Deployment metadata:
name: deploymentexample
spec:
replicas: 3
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.10
通过yaml创建Deployment 服务
func YamlLbNgxin ¶
func YamlLbNgxin()
部署一个nginx的负载均衡服务器 使用容器方式运行nginx,并使用k8s管理 在容器内部跑agent,去配置nginx,主要 一个集群一个nginx,或haproxy提供服务,内部服务注册发现的不需要配置 信息放到redis里面,agent监控redis变化实现配置更新 由master服务往redis里面放置数据 1、对k8s service
Types ¶
type AppPodStatus ¶
type AppPodStatus struct {
// 应用名称
AppName string
// 镜像名称
Image string
// 配置信息
Cpu string
Memory string
// 宿主机地址
HostIp string
// 容器IP
PodIp string
// 状态
Status bool
// 重启次数
RestartCount int32
// 资源名称
ResourceName string
// 集群名称
ClusterName string
// 容器ID
ContainerId int
// 创建时间
CreateTime string
// 容器名称
ContainerName string
}
func GetPodStatus ¶
func GetPodStatus(namespace string, clientSet kubernetes.Clientset) []AppPodStatus
获取某个namespace下面的服务
type AutoScaleParam ¶
type AutoScaleParam struct {
ReplicasMax int32
ReplicasMin int32
Cpu int64
Memory int64
CreateUser string
ResourceName string
}
2018-02-19 14:50 获取自动扩容的扩容数量参数
type CertData ¶
type CertData struct {
// ca证书公钥文件
CaData string
// node证书公钥内容
CertData string
// node证书私钥内容
KeyData string
}
2018-03-01 14:24 获取集群证书文件
type CloudApp ¶
type CloudApp struct {
//
AppId int64
//应用名称
AppName string
//运行状态
Status string
//最近修改时间
LastModifyTime string
//应用标签
AppLabels string
//其他非固定数据存储
JsonData string
//应用类型
AppType string
//资源空间
ResourceName string
//创建时间
CreateTime string
//创建用户
CreateUser string
//最近修改用户
LastModifyUser string
//最近更新时间
LastUpdateTime string
// 容器数量
ContainerNumber int
// 集群名称
ClusterName string
// 失败的容器数量
ContainerFail int
// 失败的服务数量
ServiceFail int
// 服务总量
ServiceNumber int
// 域名
Domain string
// svc + namespace:8888
// 访问方式
Access []string
// 镜像名称
Image string
// 服务名称
ServiceName string
// 服务ID
ServiceId int64
// 正在运行的数量
AvailableReplicas int32
// 环境名称
Entname string
// 检查时间
CheckTime int64
}
func GetNamespaceApp ¶
func GetNamespaceApp(clientset kubernetes.Clientset) []CloudApp
获取自己创建的namespace应用, 规则是app名加资源名区分
type CloudAutoScaleLog ¶
type CloudAutoScaleLog struct {
//
LogId int64
//创建时间
CreateTime string
//指标类型
MetricType string
//缩容步长
ReduceStep int64
//扩展到
Replicas int64
//指标名称
MetricName string
//es连接地址
Es string
//扩容状态,成功失败
Status string
//监控值
MonitorValue float64
//最小值
ReplicasMin int32
//扩容步长
IncreaseStep int64
//最大值
ReplicasMax int32
//扩容或缩容间隔
ActionInterval int64
//查询参数
Query string
//应用名称
AppName string
//集群名称
ClusterName string
//最近几次超过阈值
LastCount int64
// 配置的阈值
Gt int64
// 步长
Step string
// 服务名称
ServiceName string
// 环境名称
Entname string
}
2018-02-20 09:39:59.7024273 +0800 CST
type CloudClusterHosts ¶
type CloudConfigureMount ¶
type CloudConfigureMount struct {
//首次挂载时间
CreateTime string
//
MountId int64
//配置文件名称
ConfigureName string
//命名空间
Namespace string
//集群名称
ClusterName string
//最近更新时间
LastUpdateTime string
// 数据名称
DataName string
// 挂载路径
MountPath string
//
ServiceName string
}
2018-01-18 10:45:25.5832512 +0800 CST
type CloudImage ¶
type CloudImage struct {
//创建用户
CreateUser string
//镜像名称
Name string
//所属仓库
Repositories string
//镜像类型,分为共有和私有
ImageType string
//
ImageId int64
//创建时间
CreateTime string
//镜像大小
Size int64
//镜像仓库组
RepositoriesGroup string
// tag数量
TagNumber int
// 访问方式
Access string
// 镜像层数
LayersNumber int
// 版本数据
Tags string
// 下载次数
Download int64
}
2018-01-27 15:08:36.2055048 +0800 CST
type CloudImageSyncLog ¶
type CloudImageSyncLog struct {
//镜像仓库组
RegistryGroup string
//仓库服务器2
RegistryServer2 string
//项目名称
ItemName string
//
LogId int64
//执行内容
Messages string
//创建用户
CreateUser string
//创建时间
CreateTime string
//程序运行时间
Runtime int64
//仓库服务器1
RegistryServer1 string
// 版本号
Version string
// 同步状态
Status string
}
2018-02-06 10:40:26.9362807 +0800 CST
type CloudLb ¶
type CloudLb struct {
//负载均衡名称
LbName string
//域名前缀
LbDomainPrefix string
//域名后缀
LbDomainSuffix string
//集群名称
ClusterName string
//资源空间
ResourceName string
//最近修改时间
LastModifyTime string
//创建用户
CreateUser string
//最近修改用户
LastModifyUser string
//
Status string
//IP地址
LbIp string
//负载均衡类型,nginx,haproxy
LbType string
//
LbId int64
//配额描述信息
Description string
//创建时间
CreateTime string
//
ServiceNumber int64
// 环境名称
Entname string
// cpu
Cpu string
// Memory
Memory string
// 日志挂载路径
HostLogPath string
}
type CloudLbCert ¶
type CloudLbCert struct {
//描述信息
Description string
//
CertId int64
//创建时间
CreateTime string
//最近修改时间
LastModifyTime string
//最近修改用户
LastModifyUser string
//证书名称
CertKey string
//证书内容
CertValue string
//创建用户
CreateUser string
// 证书公钥文件
PemValue string
}
2018-02-02 10:01:17.2337629 +0800 CST
type CloudLbNginxConf ¶
type CloudLbNginxConf struct {
//
ConfId int64
//创建用户
CreateUser string
//参考lb服务id
LbServiceId string
//资源空间
ResourceName string
//应用名称
AppName string
//集群名称
ClusterName string
//最近修改时间
LastModifyTime string
// 最近修改人
LastModifyUser string
//域名
Domain string
//vhost数据
Vhost string
//创建时间
CreateTime string
//服务名称
ServiceName string
// 负载服务ID
ServiceId int64
// 使用证书名称
CertFile string
}
2018-02-01 13:32:07.5158035 +0800 CST
type CloudLbService ¶
type CloudLbService struct {
//转到容器的端口
ContainerPort string
//要负载的服务的名称
ServiceName string
//负载均衡名称
LbName string
//证书文件
CertFile string
//服务描述信息
Description string
//监听端口
ListenPort string
//负载均衡类型,tcp,http,https
LbType string
//集群名称
ClusterName string
//最近修改用户
LastModifyUser string
//
ServiceId int64
//最近修改时间
LastModifyTime string
//创建时间
CreateTime string
//创建用户
CreateUser string
// 访问地址
Domain string
// 应用名称
AppName string
// 资源空间
ResourceName string
// 应用服务对应的ID
LbServiceId string
// 负载均衡的ID
LbId int64
// 是否配置默认域名
DefaultDomain string
// 负载方式 pod node
LbMethod string
// 负载协议
Protocol string
// 服务版本
ServiceVersion string
// 环境名称
Entname string
// 流量切入百分比
Percent int
// 流量切入名称
FlowServiceName string
}
type CloudStorage ¶
type CloudStorage struct {
//
StorageId int64
//最近修改时间
LastModifyTime string
//创建时间
CreateTime string
//创建用户
CreateUser string
//描述信息
Description string
//存储大小,单位GB
StorageSize string
//存储格式
StorageFormat string
//最近修改用户
LastModifyUser string
//集群名称
ClusterName string
//glusterfs, nfs, host
StorageType string
// 名称
Name string
// 服务器地址
StorageServer string
// 使用装态
Status string
// 环境名称
Entname string
SharedType string
}
2018-01-18 16:23:05.0430682 +0800 CST
type CloudStorageMountInfo ¶
type CloudStorageMountInfo struct {
//服务名称
ServiceName string
//应用名称
AppName string
//创建用户
CreateUser string
//存储服务器
StorageServer string
//读写权限
Model string
//存储类型
StorageType string
//
MountId int64
//创建时间
CreateTime string
//集群名称
ClusterName string
//容器挂载路径
MountPath string
// 资源空间
ResourceName string
// 挂载状态
Status string
// 存储卷名称
StorageName string
}
2018-01-31 10:10:22.9723601 +0800 CST
type ClusterHealth ¶
type ClusterResources ¶
type ClusterResources struct {
UsedCpu int64
UsedMem int64
CpuUsePercent float64
MemUsePercent float64
MemFree int64
CpuFree int64
Cpu int64
Mmeory int64
Services int
}
func GetClusterUsed ¶
func GetClusterUsed(clientset kubernetes.Clientset) ClusterResources
获取资源使用情况,cpu,内存
type ClusterStatus ¶
type ClusterStatus struct {
ClusterId int64
ClusterType string
NodeStatus
ClusterAlias string
ClusterName string
Nodes int64
Services int
OsVersion string
}
func GetNodeFromCluster ¶
func GetNodeFromCluster(clientSet kubernetes.Clientset) ClusterStatus
type ConfigureData ¶
type ConfigureData struct {
ContainerPath string
DataName string
DataId string
ConfigDbData map[string]interface{}
}
配置文件信息 2018-01-17 21:34
type EventData ¶
type EventData struct {
// 事件事件
EventTime string
// 信息
Messages string
// 原因
Reason string
// 主机Ip
Host string
// 类型
Type string
}
2018-02-27 20:51
type HealthData ¶
type HealthData struct {
// 检查类型
HealthType string
// 检查端口
HealthPort string
// http访问路径
HealthPath string
// 服务启动预计时间
HealthInitialDelay string
// 检查间隔
HealthInterval string
// 失败阈值
HealthFailureThreshold string
// 检查超时
HealthTimeout string
// 通过命令检查
HealthCmd string
}
配置服务健康检查使用的
type HostImages ¶
2018-02-13 09:46 镜像数据,
func GetNodeImage ¶
func GetNodeImage(clustername string, ip string) []HostImages
2018-02-13 09:54 获取某个节点的镜像
type ImagePushParam ¶
type ImagePushParam struct {
// 仓库IP
Registry1Ip string
Registry2Ip string
// 仓库域名
Registry1Domain string
Registry2Domain string
// 仓库端口
Registry1Port string
Registry2Port string
// user:pass b64
Registry2Auth string
Registry1Auth string
// 仓库组
RegistryGroup string
// 项目名
ItemName string
// 版本号
Version string
// 操作用户
User string
// 启动时间
CreateTime string
// 容器id
ContainerId string
// 操作类型
Type string
// 服务器地址
ServerAddress string
}
镜像推送使用的参数 2018-02-06 08:13
type JobParam ¶
type JobParam struct {
// job 名称
Jobname string
// 执行命令
Command []string
// 超时时间
Timeout int
// master地址
Master string
// master 端口
Port string
// docker file
Dockerfile string
// 镜像仓库 // 编译完提交镜像
RegistryServer string
// 限制进程数据
NoProcMax string
NoProcMin string
// 限制文件数据
NoFileMax string
NoFileMin string
// 项目名称
Itemname string
// 版本
Version string
// 仓库认证密码
Auth string
// namespace
Namespace string
// 镜像服务域名
RegistryDomain string
// 镜像服务IP地址
RegistryIp string
// 仓库组地址
RegistryGroup string
// 镜像地址
Images string
// 配置文件
ConfigureData []ConfigureData
// job分配cpu
Cpu int
// 内存分配大小
Memory int
// 不能创建或更新configmap
NoUpdateConfigMap bool
// 私有仓库地址
RegistryAuth string
// 集群名称
ClusterName string
// 认证服务器IP地址
AuthServerIp string
// 认证服务器域名
AuthServerDomain string
// 构建脚本
Script string
// 环境变量
Env string
// 类型
Type string
// 服务器地址
ServerAddress string
}
2018-01-25 10:51
type NodeReport ¶
type NodeReport struct {
//
Ip string
Namespace string
Name string
CpuRequests string
MemoryRequests string
CpuLimits string
MemoryLimits string
}
2018-09-04 09:51 集群节点资源使用情况
func DescribeNodeResource ¶
func DescribeNodeResource(clientSet kubernetes.Clientset, ip string) []NodeReport
type NodeSelector ¶
选择节点配置 2018-01-11 15;57 只能选择一个机器 kubernetes.io/hostname=
type NodeStatus ¶
type NodeStatus struct {
hosts.CloudClusterHosts
Lables []string
K8sVersion string
ErrorMsg string
MemSize int64
OsVersion string
}
func GetNodesFromIp ¶
func GetNodesFromIp(ip string, clientset kubernetes.Clientset, nodes []v1.Node) NodeStatus
获取nodes状态数据
type PortData ¶
type PortData struct {
// 标签名称,主要是主机名称
NodePort string
// 容器端口
ContainerPort string
// 集群内端口
Port string
// 访问类型,集群内, 集群外,集群内外
Type string
}
获取服务和pod的映射端口数据 2018-01-12 15:36
type QueryParam ¶
type QueryParam struct {
// 集群名称
ClusterName string
// 服务名称
ServiceName string
// 应用名称
AppName string
// namespace
Namespace string
// prometheus 主机IP地址
Host string
// prometheus api端口
Port string
// 开始时间
Start string
// 结束时间
End string
// 步长
Step string
// 查询参数
Query string
// 最近几次超过阈值
LastCount int
// 阈值大于多少
Gt int64
// 阈值小于多少
Lt int64
// 操作,是扩容还是缩容,还是不操作, increase | reduce | none
LtAction string
// 阈值大于成立
GtTrue bool
// 阈值小成立
LtTrue bool
// 扩容步长
IncreaseStep int32
// 扩容或缩容间隔
Interval time.Duration
// 操作间隔
ActionInterval int64
// 扩容
// 服务版本
ServiceVersion string
// es地址
Es string
// 数据源来源
DataSource string
// 指标名称,系统自带
MetricName string
// 监控值
MonitorValue float64
// 环境名称
Entname string
}
sum(rate(container_cpu_usage_seconds_total{id="/",instance=~"^.*$"}[1m])) / sum (machine_cpu_cores{instance=~"^.*$"}) * 100 cpu使用率 sum (container_memory_working_set_bytes{id="/",instance=~"^.*$"}) / sum (machine_memory_bytes{instance=~"^.*$"}) * 100 内存使用率 query:sum(rate(container_cpu_usage_seconds_total{image!="",name=~"^k8s_.*",instance=~"^.*$",namespace=~"^kube-system$"}[1m])) by (pod_name)
type RegistryLock ¶
type RegistryParam ¶
type RegistryParam struct {
Name string
ClusterName string
Master string
Port string
AuthServer string
HostPath string
Replicas int64
}
仓库创建使用参数 2018-01-21 15:55
type RollingParam ¶
type RollingParam struct {
MinReadySeconds int32
TerminationGracePeriodSeconds int64
MaxSurge int32
Namespace string
Name string
Client kubernetes.Clientset
Images string
}
2018-02-16 18:36 服务滚动更新参数
type ServiceParam ¶
type ServiceParam struct {
// 客户端
C1 *dynamic.Client
// 命名空间
Namespace string
// 服务名称
Name string
// deploy名称
ServiceName string
// 网络模式
NetworkMode string
// cpu
Cpu interface{}
// 内存
Memory string
// 容器暴露端口
Port string
// 存储数据
StorageData string
// 镜像名称
Image string
// 标签选择器
Selector string
// 亲和性数据
// 环境变量数据
Envs string
// 副本数量
Replicas int64
// 健康检查数据
HealthData string
// 客户端
Cl2 *dynamic.Client
// 端口数据
PortData string
// 获取数据客户端
Cl3 kubernetes.Clientset
// 更新类型
Update bool
// 滚动升级时候,会优先启动的pod数量
MaxSurge int
MaxUnavailable int
// 指定没有任何容器crash的Pod并被认为是可用状态的最小秒数
MinReady int
// 更新类型
UpdateType string
// 已经存在的端口数据
OldPort util.Lock
// 配置文件key
ConfigureData []ConfigureData
// 集群名称
ClusterName string
// 容器启动命令[]string
Command string
// 镜像仓库的
// 集群主机IP
Master string
//
MasterPort string
// 资源空间
ResourceName string
// 应用名称
AppName string
// 创建用户
CreateUser string
// 配置文件是否更新参数
NoUpdateConfig bool
// 主机端口
HostPort string
// 安全设置
Privileged bool
// 镜像仓库地址
Registry string
// 镜像仓库用户名密码 admin:admin
RegistryAuth string
// 最大扩容量
ReplicasMax int64
// 标签
Labels map[string]interface{}
// 访问状态
AccessMode string
// 老的yaml信息,主要是获取端口
PortYaml string
// 重建标志
IsRedeploy bool
// pod关闭时间
TerminationSeconds int
// session 亲和性
SessionAffinity string
// kafka 地址
Kafka string
// 日志路径,文件或目录,目录以/结尾
LogPath string
// 环境名称
Ent string
// es地址
ElasticSearch string
// 日志挂载路径
LogDir string
}
创建服务参数文件 2018-01-11 21:02
type ServicePod ¶
type ServicePod struct {
// 容器端口
ContainerPort []int32
// 应用名称
AppName string
// 集群名称
ClusterName string
// 容器名称
ContainerName string
// 协议类型
Protocol string
// 选择器
Selector map[string]string
// 资源空间
ResouceName string
}
func GetPodsFromUUid ¶
func GetPodsFromUUid(namespace string, uuid string, clientSet kubernetes.Clientset) []ServicePod
获取某个uuid标签的下面的pod服务 在创建完pod后自动创建service使用
type StorageData ¶
type StorageData struct {
// 宿主机路径
HostPath string
// 容器挂载路径
ContainerPath string
// 分布式卷名称
Volume string
// 读写权限
Model int
// 只读挂载
ReadOnly bool
}
配置服务存储数据
type StorageParam ¶
type StorageParam struct {
// 存储名称
Name string
// 存储大小
Size string
// 访问模式
AccessMode string
// 集群MasterIP
Master string
// 集群MasterPort
Port string
//
Namespace string
// pvc name
PvcName string
// 宿主机地址
HostPath string
// pvc类型
StorageType string
// 集群名称
ClusterName string
}
2018-01-29 14:28 创建nfs存储
type UpdateLbNginxUpstream ¶
type UpdateLbNginxUpstream struct {
Master string
Port string
Domain string
Namespace string
ServiceName string
V CloudLbService
ClusterName string
}
2018-02-17 21:09 更新upstream,参数