ReplicationController

简要概述

staging/src/k8s.io/api/core/v1/types.go

查看官方介绍

该资源已废弃,被 ReplicaSet 替代。

常用指令

TODO;

配置示例

  • 通过 kubectl 创建

无法直接通过命令行创建该资源,可先创建 Deployment 然后以此为模版更改 yaml 内容。

kubectl create deployment busybox \
	--replicas=3 \
	--image=registry.cn-hangzhou.aliyuncs.com/opsaid/busybox:1.35.0 \
	--dry-run=client \
	-o yaml \
	-- /bin/sh -c "sleep 3600"

更改 apiVersionv1kindReplicationController 同时移除生成 yaml 中 matchLabelsstrategystatus 三个属性。

  • 通过 yaml 创建
apiVersion: v1
kind: ReplicationController
metadata:
  creationTimestamp: null
  labels:
    app: busybox
  name: busybox
spec:
  replicas: 3
  selector:
    app: busybox
    #matchLabels:
    #  app: busybox
  #strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: busybox
    spec:
      containers:
      - command:
        - /bin/sh
        - -c
        - sleep 3600
        image: registry.cn-hangzhou.aliyuncs.com/opsaid/busybox:1.35.0
        name: busybox
        resources: {}
#status: {}

数据结构

ReplicationController

// ReplicationController represents the configuration of a replication controller.
type ReplicationController struct {
    metav1.TypeMeta `json:",inline"`

    // If the Labels of a ReplicationController are empty, they are defaulted to
    // be the same as the Pod(s) that the replication controller manages.
    // Standard object's metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
    // +optional
    metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`

    // Spec defines the specification of the desired behavior of the replication controller.
    // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
    // +optional
    Spec ReplicationControllerSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"`

    // Status is the most recently observed status of the replication controller.
    // This data may be out of date by some window of time.
    // Populated by the system.
    // Read-only.
    // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
    // +optional
    Status ReplicationControllerStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"`
}

ReplicationControllerSpec

// ReplicationControllerSpec is the specification of a replication controller.
type ReplicationControllerSpec struct {
    // Replicas is the number of desired replicas.
    // This is a pointer to distinguish between explicit zero and unspecified.
    // Defaults to 1.
    // More info: https://kubernetes.io/docs/concepts/workloads/controllers/replicationcontroller#what-is-a-replicationcontroller
    // +optional
    Replicas *int32 `json:"replicas,omitempty" protobuf:"varint,1,opt,name=replicas"`

    // Minimum number of seconds for which a newly created pod should be ready
    // without any of its container crashing, for it to be considered available.
    // Defaults to 0 (pod will be considered available as soon as it is ready)
    // +optional
    MinReadySeconds int32 `json:"minReadySeconds,omitempty" protobuf:"varint,4,opt,name=minReadySeconds"`

    // Selector is a label query over pods that should match the Replicas count.
    // If Selector is empty, it is defaulted to the labels present on the Pod template.
    // Label keys and values that must match in order to be controlled by this replication
    // controller, if empty defaulted to labels on Pod template.
    // More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#label-selectors
    // +optional
    // +mapType=atomic
    Selector map[string]string `json:"selector,omitempty" protobuf:"bytes,2,rep,name=selector"`

    // TemplateRef is a reference to an object that describes the pod that will be created if
    // insufficient replicas are detected.
    // Reference to an object that describes the pod that will be created if insufficient replicas are detected.
    // +optional
    // TemplateRef *ObjectReference `json:"templateRef,omitempty"`

    // Template is the object that describes the pod that will be created if
    // insufficient replicas are detected. This takes precedence over a TemplateRef.
    // More info: https://kubernetes.io/docs/concepts/workloads/controllers/replicationcontroller#pod-template
    // +optional
    Template *PodTemplateSpec `json:"template,omitempty" protobuf:"bytes,3,opt,name=template"`
}

PodTemplateSpec

参考 Pod 资源。

ReplicationControllerStatus

// ReplicationControllerStatus represents the current status of a replication
// controller.
type ReplicationControllerStatus struct {
    // Replicas is the most recently oberved number of replicas.
    // More info: https://kubernetes.io/docs/concepts/workloads/controllers/replicationcontroller#what-is-a-replicationcontroller
    Replicas int32 `json:"replicas" protobuf:"varint,1,opt,name=replicas"`

    // The number of pods that have labels matching the labels of the pod template of the replication controller.
    // +optional
    FullyLabeledReplicas int32 `json:"fullyLabeledReplicas,omitempty" protobuf:"varint,2,opt,name=fullyLabeledReplicas"`

    // The number of ready replicas for this replication controller.
    // +optional
    ReadyReplicas int32 `json:"readyReplicas,omitempty" protobuf:"varint,4,opt,name=readyReplicas"`

    // The number of available replicas (ready for at least minReadySeconds) for this replication controller.
    // +optional
    AvailableReplicas int32 `json:"availableReplicas,omitempty" protobuf:"varint,5,opt,name=availableReplicas"`

    // ObservedGeneration reflects the generation of the most recently observed replication controller.
    // +optional
    ObservedGeneration int64 `json:"observedGeneration,omitempty" protobuf:"varint,3,opt,name=observedGeneration"`

    // Represents the latest available observations of a replication controller's current state.
    // +optional
    // +patchMergeKey=type
    // +patchStrategy=merge
    Conditions []ReplicationControllerCondition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,6,rep,name=conditions"`
}

ReplicationControllerCondition

type ReplicationControllerConditionType string

// These are valid conditions of a replication controller.
const (
    // ReplicationControllerReplicaFailure is added in a replication controller when one of its pods
    // fails to be created due to insufficient quota, limit ranges, pod security policy, node selectors,
    // etc. or deleted due to kubelet being down or finalizers are failing.
    ReplicationControllerReplicaFailure ReplicationControllerConditionType = "ReplicaFailure"
)

// ReplicationControllerCondition describes the state of a replication controller at a certain point.
type ReplicationControllerCondition struct {
    // Type of replication controller condition.
    Type ReplicationControllerConditionType `json:"type" protobuf:"bytes,1,opt,name=type,casttype=ReplicationControllerConditionType"`
    // Status of the condition, one of True, False, Unknown.
    Status ConditionStatus `json:"status" protobuf:"bytes,2,opt,name=status,casttype=ConditionStatus"`
    // The last time the condition transitioned from one status to another.
    // +optional
    LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty" protobuf:"bytes,3,opt,name=lastTransitionTime"`
    // The reason for the condition's last transition.
    // +optional
    Reason string `json:"reason,omitempty" protobuf:"bytes,4,opt,name=reason"`
    // A human readable message indicating details about the transition.
    // +optional
    Message string `json:"message,omitempty" protobuf:"bytes,5,opt,name=message"`
}

ConditionStatus

参考 Pod 资源。