Resources for deploying various Kubernetes entities, these resources are designed to be ran on the kubernetes master but can be ran anywhere that has access to a kubernetes api by changing the ['kubernetes']['master']['ip']
attribute. These resources utilize the kubeclient ruby gem and run against the v1beta1 api.
Currently broken resources: (waiting on support for v1 api through kubeclient gem)
- Kubernetes Pod (
kube_pod
) - Kubernetes Replication Controller (
kube_replication_controller
) - Kubernetes Service (
kube_service
)
- All platforms where kubeclient gem can be installed
- Chef 12.9+
- build-essential
['kubernetes']['master']['ip']
- the address used when contacting the kubernetes api['kubernetes']['master']['port']
- the port that will be used when contacting the kubernetes api['kubernetes']['client_version']
- the version of the kubeclient gem to install
Manage a standalone Kubernetes pod, there is no redundancy in a pod and is simply used to specify a group of containers to be jointly deployed on a host.
create
- default. ensures the pod is createddestroy
- ensures the pod does not exist
id
- name attribute. The identifier used when managing the podcontainers
- required a hash of container information that will be used when creating the podvolumes
- a hash of volume information used when specifying storage for containerslabels
- specify the labels that will be added to the pod
kube_pod "my-pod" do
containers({
name: 'pod-member',
image: 'my/image'
})
labels "aww=yiss"
action [:destroy,:create]
end
Replication controllers are used to maintain a consistent amount of a pod at any given time using selector labels
create
- default. ensures the replication controller is createddestroy
- ensures the replication controller does not exist
id
- name attribute. The identifier used when managing the replication controllercontainers
- required a hash of container information that will be used when the replication controller needs to generate new podsvolumes
- a hash of volume information used in generating new podsselector
- how the replication controller will ensure that enough replicas existpod_labels
- specify the labels added to the individual pods that are spawned offlabels
- specify the labels that will be added to the replication controller
kube_replication_controller "master-controller" do
containers({
name: 'redis-master',
image: 'dockerfile/redis'
})
replicas 2
selector 'role' => 'master','app' => 'redis'
labels ['aww=yiss','motha-freakin=breadcrumbs']
action [:destroy,:create]
end
Deploy a Kubernetes service, which can be used as a basic container load balancer that routes traffic based on selector labels
create
- default. ensure the service existsdestroy
- ensure the service does not exist
id
- name attribute. The identifier used when managing the serviceport
- required the port that the service will listen on for trafficcontainer_port
- what port the service will route to on the selected containers defaults to the port that the service is listening onselector
- labels that the service will use when choosing containers to route traffic tolabels
- labels that will be added to the service
kube_service "backend-service" do
port 8005
selector 'role' => 'backend'
end
The syntax used when specifying containers and volumes is specific to the kubernetes api, for examples on what these can/should look like please see the kubernetes documentation/examples.
Theres a bit of magic in the helper library that allows you to specify labels as either a hash 'this' => 'that', 'app' => 'redis'
, an array of labels ['this=that','app=redis']
, or a comma delimited string 'this=that,app=redis'
. All three will be treated as the same thing when writing your resources.
- Author:: Andre Elizondo (andre@chef.io)
Copyright 2015, Chef Software, Inc.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.