当前位置:网站首页>Extending kubernetes API with CRD
Extending kubernetes API with CRD
2022-06-22 02:27:00 【Mr.Cylon】
Intorduction CRD
What is? CRD
stay Kubernetes API in ,resources Is stored API Object collection endpoint. for example , built-in Pod resource contain Pod A collection of objects . When we want to expand API, Native Kubernetes Can't meet our needs , At this time CRD (CustomResourceDefinition) And that's what happened . stay Kubernetes Created in CRD after , You can use it like any other native Kubernetes Use it like an object , Thus make use of Kubernetes All functions of 、 Such as security 、API service 、RBAC etc. .
Kubernetes 1.7 After that, I added the right CRD Customize the secondary development capability of resources to expand Kubernetes API, adopt CRD We can approach Kubernetes API Add new resource type , Without modification Kubernetes Source code to create custom API server, This feature greatly improves Kubernetes The ability to expand .
establish CRD
Prerequisite : Kubernetes The server version must be at least version 1.16
Create a new CustomResourceDefinition(CRD) when ,Kubernetes API The server generates a for each version specified RESTful The resource path of .( That is to define a Restful API).CRD It can be namespace Scoped , It can also be cluster Scoped , Depending on CRD Of scope Field settings . Like other existing built-in objects , Delete one namespace when , The namespace All custom objects under will also be deleted .CustomResourceDefinition It is not limited by the name space , Available for all namespaces .
for example , Write a firewall port The rules :
# 1.16 Fixed format after version
apiVersion: apiextensions.k8s.io/v1
# type crd
kind: CustomResourceDefinition
metadata:
# It has to be for name=spec.names.plural + spec.group
name: ports.firewalld.fedoraproject.org
spec:
# api Medium group
# /apis/<group>/<version>/<plural>
group: firewalld.fedoraproject.org
# this crd Act on Optional Namespaced|Cluster
scope: Namespaced
names:
# Plural form of first name , be used for api
plural: ports
# The singular form of the name . For command line
singular: port
# species , Resource list type
kind: PortRule
# Short name , Similar permission CLI A resource that matches a shorter string on the
shortNames:
- fp
versions:
# Define the type of version
- name: v1
# adopt served Flag to enable or disable
served: true
# One and only one version must be marked as a storage version
storage: true
# Customize the default authentication mode of resources
schema:
# Version used
openAPIV3Schema:
# Define a parameter as an object type
type: object
# The type of this parameter
properties:
# Parameter properties spec
spec:
# spec The type of attribute is object
type: object
# Object properties
properties:
# spec attribute name
name:
# The type is string
type: string
port:
type: integer
host:
type: string
isPermanent:
type: boolean
It should be noted that v1.16 The version has been GA 了 , It uses v1 edition , Before is vlbeta1, There are some changes in the definition specification , So pay attention to version changes .
The definition of this place is similar to our definition of common resource objects , We say we can define a custom resource object at will , But when creating resources , Certainly not to let us write at will YAML Of documents , When we put the above CRD The document is submitted to Kubernetes after ,Kubernetes The declaration documents submitted by us will be verified , As can be seen from the definition CRD Is based on OpenAPIv3 schem Carry out standardized . Of course, this verification is just Verify the type of field , It's junior , If you want more complex verification , This is the time to pass Kubernetes Of admission webhook To implement the . More usage of validation , You can go to the official documents to view .
Create a crd Type resources
apiVersion: "firewalld.fedoraproject.org/v1"
kind: PortRule
metadata:
name: http-port
spec:
name: "nginx"
port: 80
host: "10.0.0.3"
isPermanent: false
View the created crd
# kubectl get t
NAME CREATED AT
firewallds.port.fedoraproject.org 2022-06-19T09:27:09Z
Reference
边栏推荐
- 微信小程序影视评论交流平台系统毕业设计毕设(4)开题报告
- Development of power plant compliance test system with LabVIEW
- excel常用快捷键excel快捷键汇总
- Chapter 19 signal lamp image simulation control technology based on speech recognition
- Object detection -- how to use labelimg annotation tool
- Wechat applet Film & TV Review Exchange Platform System Graduation Design (4) Rapport d'ouverture
- Wechat applet film and television review and exchange platform system graduation design (1) development outline
- Input system learning ----- inputfilter
- Shadertoy realizes simple compass
- Leetcode 41 - 45 dynamic planning topic
猜你喜欢

FPGA-Xilinx 7系列FPGA DDR3硬件设计规则

Review of mathematical knowledge: triple integral

Chapter 24 image and video processing based on Simulink -- matlab in-depth learning and practical collation

Common shortcut keys in Excel summary of shortcut keys in Excel

MATLAB 学习笔记(5)MATLAB 数据的导入和导出

Introduction to Apache ActiveMQ Artemis

Excel Common shortcut keys Excel shortcut keys Summary

微信小程序影视评论交流平台系统毕业设计毕设(3)后台功能

An error occurs when Android uses the SQL database to login. Attempt to invoke virtual method '' on a null object reference

Chrome browser cancel input box to record form input history
随机推荐
Chapter 25 digital watermarking technology based on Wavelet Transform
EMC整改小技巧
Asemi Schottky diode 1N5819 parameters, 1N5819 replacement, 1N5819 source
如何获取GBase8a数据库中表、列的comment备注信息?
Shadertoy realizes simple compass
atguigu----收集表单数据
Unicode decodeerror appears: 'ASCII' codec can't decode byte 0xe9 in position 0: ordinal not in range solution
目标检测之——labelImg标注工具使用方法
微信小程序影视评论交流平台系统毕业设计毕设(5)任务书
Leetcode 513 find the value in the lower left corner of the tree [bfs binary tree] the leetcode path of heroding
Zap grammar sugar
Chapter 19 signal lamp image simulation control technology based on speech recognition
Software Test Engineer Interview interface test FAQ
博途PLC和CODESYS平台下FB编程(如何实现100路FB循环遍历执行)
数组常用方法
Learn to crawl steadily 08 - detailed explanation of the use method of selenium
Completion of graduation design of wechat small program film and television review and exchange platform system (5) assignment
idea----bookmark
软件测试工程师面试接口测试常见问题
Global exception handling