Class: EksCli::K8s::Client
- Inherits:
-
Object
- Object
- EksCli::K8s::Client
show all
- Defined in:
- lib/eks_cli/k8s/client.rb
Constant Summary
collapse
- TIMEOUTS =
{open: 10, read: 20}
Instance Method Summary
collapse
Constructor Details
#initialize(cluster_name) ⇒ Client
Returns a new instance of Client.
11
12
13
|
# File 'lib/eks_cli/k8s/client.rb', line 11
def initialize(cluster_name)
@cluster_name = cluster_name
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/eks_cli/k8s/client.rb', line 67
def method_missing(method, *args, &block)
if v1_client.respond_to?(method)
v1_client.send(method, *args, &block)
elsif apps_client.respond_to?(method)
apps_client.send(method, *args, &block)
elsif storage_client.respond_to?(method)
storage_client.send(method, *args, &block)
else
raise "unknown method #{method}"
end
end
|
Instance Method Details
#create_default_storage_class ⇒ Object
34
35
36
37
|
# File 'lib/eks_cli/k8s/client.rb', line 34
def create_default_storage_class
Log.info "creating default storage class"
Log.info self.create_storage_class(resource_from_yaml("default_storage_class.yaml"))
end
|
#create_dns_autoscaler ⇒ Object
39
40
41
42
|
# File 'lib/eks_cli/k8s/client.rb', line 39
def create_dns_autoscaler
Log.info "creating kube-dns autoscaler"
Log.info self.create_deployment(resource_from_yaml("dns_autoscaler.dep.yaml"))
end
|
#enable_gpu ⇒ Object
19
20
21
22
|
# File 'lib/eks_cli/k8s/client.rb', line 19
def enable_gpu
Log.info "installing nvidia device plugin daemon set (GPU support)"
self.create_daemon_set(resource_from_yaml("nvidia_device_plugin.yaml"))
end
|
#get_elb(service_name, ns = "default") ⇒ Object
15
16
17
|
# File 'lib/eks_cli/k8s/client.rb', line 15
def get_elb(service_name, ns = "default")
self.get_service(service_name, ns).status.loadBalancer.ingress.first.hostname
end
|
#set_docker_registry_credentials(user, password, email) ⇒ Object
24
25
26
27
28
29
30
31
32
|
# File 'lib/eks_cli/k8s/client.rb', line 24
def set_docker_registry_credentials(user, password, email)
Log.info "setting docker registry credentials"
Log.info `kubectl config use-context #{config["cluster_arn"]} &&
kubectl create secret docker-registry registrykey --docker-server=https://index.docker.io/v1/ --docker-username=#{user} --docker-password=#{password} --docker-email=#{email} &&
kubectl --namespace=kube-system create secret docker-registry registrykey --docker-server=https://index.docker.io/v1/ --docker-username=#{user} --docker-password=#{password} --docker-email=#{email}`
Log.info client.patch_service_account("default", {imagePullSecrets: [{name: "registrykey"}]}, "default")
Log.info client.patch_service_account("default", {imagePullSecrets: [{name: "registrykey"}]}, "kube-system")
end
|
#wait_for_cluster ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/eks_cli/k8s/client.rb', line 44
def wait_for_cluster
Log.info "waiting for cluster #{@cluster_name} to respond"
ready = false
while !ready
begin
res = self.get_services
if res.count > 0
Log.info "#{@cluster_name} is up and running!"
ready = true
end
rescue Kubeclient::HttpError
Log.info "couldn't connect to server, retrying..."
end
end
end
|