一、自定义资源(CustomResourceDefinitions)

1.创建一个CRD对象 kubectl create -f website-crd.yaml

apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
  name: websites.extensions.example.com
spec:
  scope: Namespaced
  group: extensions.example.com
  version: v1
  names:
    kind: Website
    singular: website
    plural: websites

2.创建自定义资源实例 kubectl create -f kubia-website.yaml

apiVersion: extensions.example.com/v1
kind: Website
metadata:
  name: kubia
spec:
  gitRepo: https://github.com/luksa/kubia-website-example.git

3.检索实例

    kubectl get websites  |  kubectl get website kubia -o yaml  kubectl describe website kubia

4.删除实例

    kubectl delete website kubia

二、自定义控制器(以pod运行)

1.创建服务账户 kubectl create serviceaccount website-controller

2.绑定集群角色

kubectl create clusterrolebinding website-controller --clusterrole=cluster-admin --serviceaccount=default:website-controller

3.部署控制器 kubectl create -f website-controller.yaml

apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: website-controller
spec:
  replicas: 1
  template:
    metadata:
      name: website-controller
      labels:
        app: website-controller
    spec:
      serviceAccountName: website-controller
      containers:
      - name: main
        image: luksa/website-controller
      - name: proxy
        image: luksa/kubectl-proxy:1.6.2

4.创建自定义对象 kubectl create -f kubia-website.yaml

5.检查控制器日志 kubectl get pod  |  kubectl logs website-controller-84bf9c9879-vrqrg -c main  kubectl get deploy,svc,po

三、验证自定义对象

四、自定义API服务器

1.API服务器聚合

2.注册一个自定义API服务器

3.创建自定义客户端

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐