apiVersion
解释: 以后所有可用的API版本
罕用的apiVersion:
v1: Kubernetes API的稳固版本,蕴含很多外围对象:pod、service等。
apps/v1: 蕴含一些通用的应用层的api组合,如:Deployments, RollingUpdates, and ReplicaSets。
batch/v1: 蕴含与批处理和相似作业的工作相干的对象,如:job、cronjob。
autoscaling/v1: 容许依据不同的资源应用指标主动调整容器。
networking.k8s.io/v1: 用于Ingress。
rbac.authorization.k8s.io/v1:用于RBAC
$ kubectl api-versions
admissionregistration.k8s.io/v1
apiextensions.k8s.io/v1
apiregistration.k8s.io/v1
apps/v1
authentication.k8s.io/v1
authorization.k8s.io/v1
autoscaling/v1
autoscaling/v2
autoscaling/v2beta1
autoscaling/v2beta2
batch/v1
batch/v1beta1
certificates.k8s.io/v1
coordination.k8s.io/v1
discovery.k8s.io/v1
discovery.k8s.io/v1beta1
events.k8s.io/v1
events.k8s.io/v1beta1
flowcontrol.apiserver.k8s.io/v1beta1
flowcontrol.apiserver.k8s.io/v1beta2
networking.k8s.io/v1
node.k8s.io/v1
node.k8s.io/v1beta1
openebs.io/v1alpha1
policy/v1
policy/v1beta1
rbac.authorization.k8s.io/v1
scheduling.k8s.io/v1
storage.k8s.io/v1
storage.k8s.io/v1beta1
v1
kind
解释: 资源对象的类型
如 pod、deployment、statefulset、job、cronjob
metadata
罕用的配置项有 name,namespace
name配置资源对象显示的名字
namespace配置归属的命名空间
spec
解释: 资源对象的具体资源清单
// 以pod为例
apiVersion: v1 #必选,版本号,例如v1
kind: Pod #必选,Pod
metadata: #必选,元数据
name: nginx #必选,Pod名称
labels: #自定义标签
app: nginx #自定义标签名字
spec: #必选,Pod中容器的具体定义
containers: #必选,Pod中容器列表,一个pod里会有多个容器
- name: nginx #必选,容器名称
image: nginx #必选,容器的镜像名称
imagePullPolicy: IfNotPresent # [Always | Never | IfNotPresent] #获取镜像的策略 Alawys示意下载镜像 IfnotPresent示意优先应用本地镜像,否则下载镜像,Nerver示意仅应用本地镜像
ports: #须要裸露的端口库号列表
- containerPort: 80 #容器须要监听的端口号
restartPolicy: Always # [Always | Never | OnFailure]#Pod的重启策略,Always示意一旦不论以何种形式终止运行,kubelet都将重启,OnFailure示意只有Pod以非0退出码退出才重启,Nerver示意不再重启该Pod
// 以Service为例
apiVersion: v1
kind: Service
metadata:
name: service-hello
labels:
name: service-hello
spec:
type: NodePort #这里代表是NodePort类型的,另外还有ingress,LoadBalancer
ports:
- port: 80 #这里的端口和clusterIP(kubectl describe service service-hello中的IP的port)对应,即在集群中所有机器上curl 10.98.166.242:80可拜访公布的应用服务。
targetPort: 8080 #端口肯定要和container裸露进去的端口对应,nodejs裸露进去的端口是8081,所以这里也应是8081
protocol: TCP # 反对TCP UDP SCTP
nodePort: 31111 # 所有的节点都会凋谢此端口30000--32767,此端口供内部调用。
selector:
run: hello #这里选择器肯定要抉择容器的标签,之前写name:kube-node是错的。
port
clusterIp:k8s集群外部拜访service的端口,即通过clusterIP: port能够拜访到某个service
nodePort:k8s集群内部拜访service的端口,通过nodeIP: nodePort能够从内部拜访到某个service。
targetPort:pod的端口,从port和nodePort来的流量通过kube-proxy流入到后端pod的targetPort上,最初进入容器。
containerPort:containerPort是pod外部容器的端口,targetPort映射到containerPort
发表回复