k8ssvc

package
v0.9.6 Latest Latest
Warning

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

Go to latest
Published: May 8, 2018 License: Apache-2.0 Imports: 19 Imported by: 5

README

FireCamp Kubernetes

FireCamp stateful services on Kubernetes is built on top of Kubernetes StatefulSet. The StatefulSet binds the storage volume with one Pod. When the Pod moves to another node, the storage volume moves as well.

FireCamp builds a few more things on top of the StatefulSet.

Manage the stateful service

FireCamp distributes the members of one stateful service across Availability Zones. When one Availability Zone goes down, the service will still work. The common mechanisms such as Security, Upgrade, Monitoring, Data Management, etc, also work for the stateful servics on Kubernetes.

Integrate with AWS network

FireCamp minimizes the dependency on the external components. FireCamp does not rely on any third party network plugin, such as Calico. FireCamp directly integrate with AWS Route53 for DNS and EC2 Secondary Private IP for the Static IP support. The application running on EC2, Container or Lambda could easily talk with the stateful service without the need to setup such as the Proxy Verb. For more details, please refer to FireCamp Architect.

Send logs to AWS CloudWatch

Kubernetes does not support the custom log driver. FireCamp deploys a Fluentd DaemonSet. The Fluentd is configured to create the log stream for each service member under the same log group. For the detail log stream and group name, please refer to the Catalog Service Log.

FireCamp Kubernetes StatefulSet

PodManagementPolicy: The ParallelPodManagement policy is used instead of OrderedReadyPodManagement. The OrderedReadyPodManagement create pods in strictly increasing order. This may introduce some issue when running in cloud. For example, Cassandra service has 3 replicas on 3 AZs. The replica0 is on AZ1. If AZ1 goes down, the pods for replica1 and 2 will keep waiting for replica0.

StatefulSetUpdateStrategy: The OnDeleteStatefulSetStrategyType is used instead of RollingUpdateStatefulSetStrategyType. As the RollingUpdateStatefulSetStrategyType is not suitable for the master-slave service, such as MongoDB, Postgres, etc. The graceful update should restart the master first, then the slaves. FireCamp will perform the update according to the service's requirement. FireCamp will track and restart the master container first for the master-slave services.

Note: this is not implemented yet. Currently the service is simply rolling updated.

How to Run FireCamp on the existing kubernetes

Currently FireCamp does not set up Kubernetes on AWS. We will integrate with AWS EKS (Elastic Container Service for Kubernetes) for the deployment once EKS is officially announced.

If you have a Kubernetes cluster in AWS, you could deploy FireCamp following below steps:

  1. Add FireCamp IAM permissions to your node. The detail IAM permissions are described in the firecamp-iamprofile.template.

  2. Add FireCamp tag to each node, tag key: firecamp-worker, value: clustername.

  3. Create the Fluentd DaemonSet to send logs to CloudWatch. Update the AWS_REGION and FIRECAMP_CLUSTER_NAME in fluentd-cw-ds.yaml, and run kubectl create -f fluentd-cw-configmap.yaml and kubectl create -f fluentd-cw-ds.yaml.

  4. Create the FireCamp manage service ReplicaSet. Update the AVAILABILITY_ZONES and CLUSTER in manageservice-replicaset.yaml, and run kubectl create -f manageservice-rbac.yaml and kubectl create -f manageservice-replicaset.yaml.

Note: Kubernetes nodes should run in all AVAILABILITY_ZONES. If one Availability Zone does not have the running node, the stateful service will fail to start. The CLUSTER should be set to the same with FIRECAMP_CLUSTER_NAME in fluentd-cw-ds.yaml.

Then you could login to any k8s node, download firecamp cli and create the stateful service.

Documentation

Index

Constants

View Source
const (
	// K8sServiceInitContainerImage is the common init container image for all services in k8s.
	K8sServiceInitContainerImage = common.OrgName + common.SystemName + "-initcontainer"
	K8sServiceStopContainerImage = common.OrgName + common.SystemName + "-stopcontainer"

	EnvInitContainerTestMode    = "TESTMODE"
	EnvInitContainerCluster     = "CLUSTER"
	EnvInitContainerServiceName = "SERVICE_NAME"
	EnvInitContainerPodName     = "POD_NAME"
)

Variables

This section is empty.

Functions

func CreateStaticIPFile added in v0.9.3

func CreateStaticIPFile(ip string) error

CreateStaticIPFile writes the static ip into file, so the container stop could delete the attached ip.

func GetStatefulSetPodNames added in v0.9.4

func GetStatefulSetPodNames(service string, replicas int64, backward bool) []string

GetStatefulSetPodNames returns the pod names of the StatefulSet service.

func IsStaticIPFileExist added in v0.9.3

func IsStaticIPFileExist() (bool, error)

IsStaticIPFileExist returns whether the static ip file exists.

func ReadStaticIP added in v0.9.3

func ReadStaticIP() (ip string, err error)

ReadStaticIP reads the member's static ip from file.

Types

type K8sInfo added in v0.9.3

type K8sInfo struct {
	// contains filtered or unexported fields
}

func NewK8sInfo added in v0.9.3

func NewK8sInfo(clustername string, fullhostname string) *K8sInfo

func (*K8sInfo) GetContainerClusterID added in v0.9.3

func (s *K8sInfo) GetContainerClusterID() string

func (*K8sInfo) GetLocalContainerInstanceID added in v0.9.3

func (s *K8sInfo) GetLocalContainerInstanceID() string

type K8sSvc

type K8sSvc struct {
	// contains filtered or unexported fields
}

K8sSvc implements the containersvc interface for kubernetes. https://kubernetes.io/docs/tasks/access-application-cluster/access-cluster

func NewK8sSvc

func NewK8sSvc(cluster string, cloudPlatform string, dbType string, namespace string) (*K8sSvc, error)

NewK8sSvc creates a new K8sSvc instance. TODO support different namespaces for different services? Wait for the real requirement.

func NewTestK8sSvc added in v0.9.3

func NewTestK8sSvc(cluster string, cloudPlatform string, namespace string, config *rest.Config) (*K8sSvc, error)

NewTestK8sSvc creates a new K8sSvc instance for test.

func (*K8sSvc) CreateReplicaSet added in v0.9.3

func (s *K8sSvc) CreateReplicaSet(ctx context.Context, opts *containersvc.CreateServiceOptions) error

CreateReplicaSet creates a k8s replicaset. Note: currently volume is skipped for ReplicaSet.

func (*K8sSvc) CreateService

func (s *K8sSvc) CreateService(ctx context.Context, opts *containersvc.CreateServiceOptions) error

CreateService creates the headless service, storage class and statefulset.

func (*K8sSvc) CreateServiceVolume added in v0.9.3

func (s *K8sSvc) CreateServiceVolume(ctx context.Context, service string, memberName string, volumeID string, volumeSizeGB int64, journal bool) (existingVolumeID string, err error)

CreateServiceVolume creates PV and PVC for the service member.

func (*K8sSvc) DeleteReplicaSet added in v0.9.3

func (s *K8sSvc) DeleteReplicaSet(ctx context.Context, service string) error

DeleteReplicaSet deletes a k8s replicaset.

func (*K8sSvc) DeleteService

func (s *K8sSvc) DeleteService(ctx context.Context, cluster string, service string) error

DeleteService deletes the service on the container platform. Expect no error (nil) if service does not exist.

func (*K8sSvc) DeleteServiceVolume added in v0.9.3

func (s *K8sSvc) DeleteServiceVolume(ctx context.Context, service string, memberName string, journal bool) error

DeleteServiceVolume deletes the pv and pvc for the service member.

func (*K8sSvc) DeleteTask

func (s *K8sSvc) DeleteTask(ctx context.Context, cluster string, service string, taskType string) error

DeleteTask deletes the task.

func (*K8sSvc) GetContainerSvcType added in v0.9.3

func (s *K8sSvc) GetContainerSvcType() string

GetContainerSvcType gets the containersvc type.

func (*K8sSvc) GetServiceStatus

func (s *K8sSvc) GetServiceStatus(ctx context.Context, cluster string, service string) (*common.ServiceStatus, error)

GetServiceStatus returns the service status.

func (*K8sSvc) GetServiceTask

func (s *K8sSvc) GetServiceTask(ctx context.Context, cluster string, service string, containerInstanceID string) (serviceTaskID string, err error)

GetServiceTask gets the service task on the container instance.

func (*K8sSvc) GetTaskStatus

func (s *K8sSvc) GetTaskStatus(ctx context.Context, cluster string, taskID string) (*common.TaskStatus, error)

GetTaskStatus gets the task status.

func (*K8sSvc) IsServiceExist

func (s *K8sSvc) IsServiceExist(ctx context.Context, cluster string, service string) (bool, error)

IsServiceExist checks if service exists. If not exist, return false & nil. If exists, return true & nil. If meets any error, error will be returned.

func (*K8sSvc) ListActiveServiceTasks

func (s *K8sSvc) ListActiveServiceTasks(ctx context.Context, cluster string, service string) (serviceTaskIDs map[string]bool, err error)

ListActiveServiceTasks lists the active (pending and running) tasks of the service.

func (*K8sSvc) RollingRestartService added in v0.9.4

func (s *K8sSvc) RollingRestartService(ctx context.Context, cluster string, service string, opts *containersvc.RollingRestartOptions) error

RollingRestartService restarts the service tasks one after the other.

func (*K8sSvc) RunTask

func (s *K8sSvc) RunTask(ctx context.Context, opts *containersvc.RunTaskOptions) (taskID string, err error)

RunTask runs a task.

func (*K8sSvc) ScaleService

func (s *K8sSvc) ScaleService(ctx context.Context, cluster string, service string, desiredCount int64) error

ScaleService scales the service containers up/down to the desiredCount. Note: it does not wait till all containers are started or stopped.

func (*K8sSvc) StopService

func (s *K8sSvc) StopService(ctx context.Context, cluster string, service string) error

StopService stops the service on the container platform, and waits till all containers are stopped. Expect no error (nil) if service is already stopped or does not exist.

func (*K8sSvc) UpdateService added in v0.9.5

func (s *K8sSvc) UpdateService(ctx context.Context, opts *containersvc.UpdateServiceOptions) error

UpdateService updates the service

Directories

Path Synopsis
Note: the example only works with the code within the same release/branch.
Note: the example only works with the code within the same release/branch.

Jump to

Keyboard shortcuts

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