react-kubernetes
v0.0.2
Published
React Renderer to manage cloud infrastructure
Downloads
12
Readme
⚠️ Currently under development, not ready for use yet
This library is currently unstable and the API is in constant change. It is being worked on in the open for better exposure, please feel free to file an issue if you have any questions or suggestions.
How to Install
npm i --save react-kubernetes
📋 Requirements
In order to use react-kubernetes
, you will need a local kubernetes environement to develop against. We recommand the installing the official Docker Dekstop that comes with kubernetes pre-installed.
The user of react-kubernetes
has to have functional knowledge of kubernetes because this library is comparable to a thin layer on top kubctl
cli.
📖 How to use ?
Here is an example of a useless cluster. We are going o create a redis pod in within a namespace. this redis pod will be available only one hour every 2 hours.
import React from 'react';
import { Cluster, Pod, Container, Volume } from 'react-bunernetes';
import { wakeYourDevOpsUpAtMidnight } from '../your/own/handler';
// First, create a Pod
const Redis = ({ name, port, maxMemory }) => {
return (
<Pod
name={name}
onFailure={() => wakeYourDevOpsUpAtMidnight()}
>
<Container
image="redis:5.0.4"
containerPort={port}
cpuLimit={0.1}
command={'redis-server "/redis-master/redis.conf"'}
>
<Volume
path="/redis-master/redis.conf"
configMap={{
port: port,
maxmemory: maxMemory,
'maxmemory-policy': 'allkeys-lru',
}}
/>
</Container>
</Pod>
);
}
// Second, use your Pod in another component if needed
const Infrastructure = () => {
const [useRedis, setUseRedis] = React.useState(false);
React.useEffect(() => {
const anHour = 1000 * 60 * 60;
setTimeout(() => {
setUseRedis(!useRedis)
}, anHour)
}, [useRedis])
return (
<Namespace name="react-kubernetes">
{useRedis && <Redis name="redis-master" port={6379} maxMemory={'10mb'}/>}
</Namespace>
)
}
// Then deploy!
// react-kubernetes will continue to manage your cluster :)
Cluster.deploy(<Infrastructure />);
🚀 How to deploy
Cluster.deploy
takes a configuration object as a second argument.
import React from 'react';
import { Cluster } from 'react-bunernetes';
import YourInfrastructure from './you/file/entry';
const kubeConfig = {
clusters: [{
name: 'my-server',
server: 'http://server.com',
}],
users: [{
name: 'my-user',
password: 'some-password',
}],
contexts: [{
name: 'my-context',
user: 'my-user',
cluster: 'my-server',
}],
currentContext: 'my-context',
};
Cluster.deploy(<YourInfrastructure />, kubeConfig);
Roadmap
- [ ] all k8s objects
- [ ] increase test coverage
- [ ] increase type coverage
📄 License
The MIT License (MIT)
Copyright 2020 Ilias Bhallil [email protected]
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.