Skip to content

Instantly share code, notes, and snippets.

@erictune
Last active December 2, 2018 02:41
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save erictune/f025f922726566a3a6045e5ae7997948 to your computer and use it in GitHub Desktop.
Save erictune/f025f922726566a3a6045e5ae7997948 to your computer and use it in GitHub Desktop.
Next Steps for viewers of "Kubernetes Extensibility", presented at Dockercon SF 2018 by Eric Tune and Tim Hockin

Activating Kubernetes for Docker

Follow Docker's activation Instructions:

Make sure you can talk to local kubernetes using kubectl before going to next steps. You should see:

$ kubectl config current-context
docker-for-desktop
$ kubectl cluster-info
Kubernetes master is running at https://localhost:6443
...

Deploy a Stack

Get a sample compose file.

$ mkdir stackdemo 
$ curl https://gist.githubusercontent.com/erictune/f025f922726566a3a6045e5ae7997948/raw/3b6a6ef6e192eb0de289c5ac6f1dba851aa653c8/docker-compose.yml > docker-compose.yml
$ kubectl get stacks
No resources found.

$ docker stack deploy --compose-file docker-compose.yml stackdemo

Waiting for the stack to be stable and running...
 - Service web has one container running
 - Service redis has one container running
Stack stackdemo is stable and running

What resources did it make?

$ kubectl get all
NAME           DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
deploy/ridis   1         1         1            1           5m

NAME                  DESIRED   CURRENT   READY     AGE
rs/ridis-85d4d69648   1         1         1         5m

NAME                        READY     STATUS    RESTARTS   AGE
po/ridis-85d4d69648-jx94k   1/1       Running   0          5m

NAME                     TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
svc/kubernetes           ClusterIP   10.96.0.1        <none>        443/TCP          29d
svc/ridis                ClusterIP   None             <none>        55555/TCP        5m
svc/ridis-random-ports   NodePort    10.101.242.155   <none>        6379:31248/TCP   5m

Explore How Docker Uses Kubernetes API Extensions

Exploring Stacks API

Let's see if kubectl knows about the stack.

$ kubectl get stacks
NAME        AGE
stackdemo   39s

Yes, it does. How is this magic possible?

Let's use a proxy to trace what kubectl is doing.

# Preferably in another shell
$ kubectl proxy -v 5 &
$ kubectl get stacks -s localhost:8001
...

Now note a line similar to this in the kubectl proxy debug output:

I0613 10:26:38.534101   82905 proxy_server.go:138] Filter accepting GET /apis/compose.docker.com/v1beta2/namespaces/default/stacks localhost

So, there is an API group called compose.docker.com with a resource type stacks. In other words, there is a stacks API on the Kubernetes API Server.

Explore Extension API Servers

How is that possible. Let's explore what APIs are part of that api server.

$ kubectl get apiservices.apiregistration.k8s.io
NAME                                   AGE
v1.                                    29d
v1.apps                                29d
...
v1beta2.compose.docker.com             29d
...

Hmm. There is one called v1beta2.compose.docker.com looks interesting. Let's investigate.

$ kubectl describe apiservices.apiregistration.k8s.io v1beta2.compose.docker.com 
Name:         v1beta2.compose.docker.com
Namespace:    
Labels:       com.docker.deploy-namespace=docker
              com.docker.fry=compose.api
              com.docker.image-tag=v0.3.0-rc4
Annotations:  <none>
API Version:  apiregistration.k8s.io/v1beta1
Kind:         APIService
Metadata:
  Creation Timestamp:  2018-05-15T13:15:35Z
  Resource Version:    410501
  Self Link:           /apis/apiregistration.k8s.io/v1beta1/apiservices/v1beta2.compose.docker.com
  UID:                 0d62fa42-5842-11e8-bb11-025000000001
Spec:
  Ca Bundle:               LS0t...0K
  Group:                   compose.docker.com
  Group Priority Minimum:  1000
  Service:
    Name:            compose-api
    Namespace:       docker
  Version:           v1beta2
  Version Priority:  16
Status:
  Conditions:
    Last Transition Time:  2018-06-01T18:04:30Z
    Message:               all checks passed
    Reason:                Passed
    Status:                True
    Type:                  Available
Events:                    <none>

Looks like this is pointing to a service. Let's check it out. It is in the docker namespace and called compose-api:

$ kubectl get service -n docker compose-api
NAME          TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)   AGE
compose-api   ClusterIP   10.110.211.86   <none>        443/TCP   28d

This is pointing to a deployment in the cluster, by the way, called compose-api:

$ kubectl get deploy -n docker
NAME          DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
compose       1         1         1            1           28d
compose-api   1         1         1            1           28d

Learn About Kubernetes API Extensibility

Read the Kubernetes Documentation:

Webhooks example:

version: "3.3"
services:
redis:
image: redis:alpine
ports:
- 6379
networks:
- frontend
deploy:
replicas: 1
networks:
frontend:
@hairyhenderson
Copy link

README.md is missing a triple-backquote right before this line:

Explore How Docker Uses Kubernetes API Extensions

@erictune
Copy link
Author

Thanks, fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment