Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kubernetes Support #3

Closed
jeyraof opened this issue Feb 5, 2020 · 7 comments
Closed

Kubernetes Support #3

jeyraof opened this issue Feb 5, 2020 · 7 comments
Labels
question Further information is requested

Comments

@jeyraof
Copy link

jeyraof commented Feb 5, 2020

Do you have a plan to support Kubernetes layer?

I think that resources frequently refered on AWS contains Ingress, Deployment, Service, StatefulSet and so on.

Thank you.

@mingrammer
Copy link
Owner

Could you please show the example code (you want) for the Kubernetes layer? :)

@mingrammer mingrammer added the question Further information is requested label Feb 5, 2020
@jeyraof
Copy link
Author

jeyraof commented Feb 5, 2020

Looks very ugly and tough, but I wish you could take my thought about this.

from diagrams import Cluster, Diagram
from diagrams.k8s import Pod
from diagrams.k8s.apps.v1 import StatefulSet, Deployment, Ingress, Service
from diagrams.k8s.apps.v1.service import NodePort
from diagrams.aws.database import RDS, ElastiCache
from diagrams.aws.network import VPC
from diagrams.aws.integration import SQS


with VPC('Service Network'):
    with Cluster('Database Cluster: Main'):
        main_db_master = RDS(name='main', type='aurora_mysql')
        main_db_master - [RDS(name='replicas')]

    with Cluster('Database Cluster: Auth'):
        auth_db_master = RDS(name='main', type='aurora_posgresql')
        auth_db_master - [RDS(name='replicas')]

    couchbase = StatefulSet(name='couchbase')

    with Cluster('Redis Cluster: cache'):
        cache_redis = [ElastiCache(name='cache_redis', type='redis'), ]

    with Cluster('Redis Clsuter: session'):
        session_redis = [ElastiCache(name='session_rdis', type='redis'), ]

    base_sqs = SQS(name='base')
    hard_sqs = SQS(name='hard')

    with Deployment('Deployment: api'):
        apis = [Pod(name='product1_api', port=3001), ]
        apis >> couchbase
        apis >> main_db_master
        apis >> auth_db_master
        apis >> cache_redis
        apis >> session_redis
        apis >> couchbase
        apis - base_sqs
        apis - hard_sqs

    with Deployment('Deployment: base_worker'):
        base_workers = [Pod(name='product1_worker_base'), ]
        base_workers >> main_db_master
        base_workers >> auth_db_master
        base_sqs - base_workers

    with Deployment('Deployment: hard_worker'):
        hard_workers = [Pod(name='product1_worker_hard'), ]
        hard_workers >> main_db_master
        hard_workers >> auth_db_master
        hard_sqs - hard_workers

    # api
    ingress = Ingress(name='ingress')
    service = Service(name='product1_service', port=3000)
    ingress >> service >> NodePort(service_port=3000, target_port=3001) >> apis

Also, I think array of instances could be represented as stacked it for scalability:

stacked = [Class(), ]

image

@mingrammer
Copy link
Owner

mingrammer commented Feb 5, 2020

Thanks for the ideas.

All node classes of diagrams are based on resource icons provided by each provider (AWS, Azure, and GCP). Fortunately, k8s also provide the icons set.

However, there are some missing icons of specific resource types such as NodePort. (only Service exists). So I can support only a limited set of k8s resources listed in the above link. :(

And this code

from diagrams.k8s import Pod
from diagrams.k8s.apps.v1 import StatefulSet, Deployment, Ingress, Service
from diagrams.k8s.apps.v1.service import NodePort

should be like this, for keeping the consistency with other providers.

from diagrams.k8s.compute import Pod, StatefulSet, Deployment
from diagrams.k8s.network import Ingress, Service

In icons set, k8s team group the resources like this as well.


+

Currently, VPC class is just a node class having VPC icon. (Cluster is the only way for grouping the nodes)

diagrams does not support grouping the resources with node classes except Cluster class. So this code does not work as you expected at least now. I need to check that this feature could be implemented with the current architecture.

with VPC():
    pass

with Deployment():
    pass

+

Graphviz does not support stacked diagram. But, It could be achieved with some hacks by making stacked icons for some (stackable) node icons). Let me think about support this feature.

@jeyraof
Copy link
Author

jeyraof commented Feb 5, 2020

Sounds good to me!
If any curiosity or relative ideas you have, please comment here.

@jeyraof jeyraof closed this as completed Feb 5, 2020
@mingrammer
Copy link
Owner

Yap! Thank you :)

@mingrammer
Copy link
Owner

mingrammer commented Feb 6, 2020

@jeyraof Diagrams v0.2.0 now supports basic Kubernetes diagrams!

Node Types

diagrams/k8s
├── clusterconfig.py
├── compute.py
├── controlplane.py
├── group.py
├── infra.py
├── network.py
├── others.py
├── podconfig.py
├── rbac.py
└── storage.py

Examples

# k8s resources
from diagrams.k8s.compute import Pod, StatefulSet
from diagrams.k8s.network import Service
from diagrams.k8s.storage import PV, PVC, StorageClass
...

@jeyraof
Copy link
Author

jeyraof commented Feb 7, 2020

What a fast are you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants