Comments (1)
- advanced
Kubernetes API resources are discovered pre-request and resource definitions are cached (configurable). This library is currently tested against k8s OpenAPI specs: 1.1x and master.
Custom Resource Definitions
Custom resources are discovered via the same mechanism as "standard" k8s resources and can be worked with as such:
Listing the Greeting
s from the hello operator
.
operation = K8s.Client.list("hello-operator.example.com/v1", :greeting, [namespace: "default"])
{:ok, greeting} = K8s.Client.run(operation, :dev)
Multiple Clusters
Copying a workloads between two clusters:
Register a staging cluster:
staging_conn = K8s.Conn.from_file("~/.kube/config")
{:ok, staging} = K8s.Cluster.Registry.add(:staging, staging_conn)
Register a prod cluster:
prod_conn = K8s.Conn.from_service_account() # or from_file/2
{:ok, prod} = K8s.Cluster.Registry.add(:prod, staging_conn)
Get a list of all deployments in the default
prod namespace:
operation = K8s.Client.list("apps/v1", :deployment, namespace: "default")
{:ok, deployments} = K8s.Client.run(operation, :prod)
Map the deployments to operations and async create on staging:
deployments
|> Enum.map(fn(deployment) -> K8s.Client.create(deployment) end)
|> K8s.Client.async(:staging)
Adding Authorization Providers
config :k8s, auth_providers: [My.Custom.Provider]
Providers are checked in order, the first to return an authorization struct wins.
Custom providers are processed before default providers.
For protocol and behavior implementation examples check out Certificate
, Token
, or AuthProvider
here.
Performing sub-resource operations
Subresource (eviction|finalize|bindings|binding|approval|scale|status) operations are created in the same way as standard operations using K8s.Operation.build/4
, K8s.Operation.build/5
, or any K8s.Client
function.
Getting a deployment's status:
cluster = :test
operation = K8s.Client.get("apps/v1", "deployments/status", name: "nginx", namespace: "default")
{:ok, scale} = K8s.Client.run(operation, cluster)
Getting a deployment's scale:
cluster = :test
operation = K8s.Client.get("apps/v1", "deployments/scale", [name: "nginx", namespace: "default"])
{:ok, scale} = K8s.Client.run(operation, cluster)
There are two forms for mutating subresources.
Evicting a pod with a Pod map:
cluster = :test
eviction = %{
"apiVersion" => "policy/v1beta1",
"kind" => "Eviction",
"metadata" => %{
"name" => "nginx",
}
}
# Here we use K8s.Resource.build/4 but this k8s resource map could be built manually or retrieved from the k8s API
subject = K8s.Resource.build("v1", "Pod", "default", "nginx")
operation = K8s.Client.create(subject, eviction)
{:ok, resp} = K8s.Client.run(operation, cluster)
Evicting a pod by providing details:
cluster = :test
eviction = %{
"apiVersion" => "policy/v1beta1",
"kind" => "Eviction",
"metadata" => %{
"name" => "nginx",
}
}
subject = K8s.Client.create("v1", "pods/eviction", [namespace: "default", name: "nginx"], eviction)
operation = K8s.Client.create(subject, eviction)
{:ok, resp} = K8s.Client.run(operation, cluster)
from k8s.
Related Issues (20)
- Question: How to get a Custom Resource?
- Question: Is there an example of Client.patch/4 available? HOT 8
- Source links in the documentation are incorrect HOT 3
- Read kube config from string
- 2.0.0-rc.1 doesn't work with kind clusters HOT 6
- Configuration of http_provider and discovery_driver is ignored HOT 13
- Large resources unusable with 2.0.0 HOT 6
- Does the watch steam handle disconnects in V2? HOT 13
- Patch strategy should be configurable HOT 5
- hostname issues HOT 7
- Streams resetting resource version HOT 4
- K8s.Conn.Config does not exist HOT 4
- Improve documentation on in-cluster connection HOT 5
- what is different between k8s lib and swarm ? HOT 2
- Support pods/logs subresource streaming HOT 5
- Exception raised when running too many get requests HOT 6
- Mint HTTPAdapter failure cycle spams errors HOT 1
- Hex.pm Usage Guide doc is unavailable HOT 2
- Http2 Adapter causing 500 requests HOT 10
- Long-lasting shell connection example is broken HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from k8s.