这是indexloc提供的服务,不要输入任何密码
Skip to content

rvmiller89/webpage-crd

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

webpage-crd

This is a sample CustomResourceDefinition (CRD) and Controller to extend the API running in Kubernetes clusters. Blog post about it here.

Usage

Download and install Kubebuilder, Kustomize, and Kind to run your Kubernetes cluster locally. I prefer Kind over Minikube since it starts up faster, but you’re welcome to use any tool to deploy your cluster.

Then compile, install, and run locally:

$ make
go build -o bin/manager main.go
$ make install
kustomize build config/crd | kubectl apply -f -
customresourcedefinition.apiextensions.k8s.io/webpages.sandbox.rvmiller.com created
$ make run
2020-07-04T22:21:21.748-0400    INFO    setup   starting manager
...

Deploy an example custom resource:

webpage.yaml

apiVersion: sandbox.rvmiller.com/v1beta1
kind: WebPage
metadata:
  name: sample-web-page
spec:
  html: |
    <html>
      <head>
        <title>WebPage CRD</title>
      </head>
      <body>
        <h2>This page served from a Kubernetes CRD!</h2>
      </body>
    </html>
$ kubectl apply -f webpage.yaml 
webpage.sandbox.rvmiller.com/sample-web-page created
$ kubectl get configmaps
NAME                     DATA   AGE
sample-web-page-config   1      10m
$ kubectl get pods
NAME                    READY   STATUS    RESTARTS   AGE
sample-web-page-nginx   1/1     Running   0          10m
$ kubectl port-forward sample-web-page-nginx 7070:80
Forwarding from 127.0.0.1:7070 -> 80
Forwarding from [::1]:7070 -> 80

Then you can see nginx serving the webpage:

About

Example CRD and Controller created with Kubebuilder

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published