undefined method `kube_apiserver' chef kubernetes

9/9/2020

I am using the latest Kube cookbook for deploying Kubernetes cluster in my environment using Chef Here is my recipe based on the Kube cookbook available in the chef supermarket

# Etcd 
etcd_service 'default' do
  action %w(create start)
end

# Kubernetes cluster

kube_apiserver 'default' do
  service_cluster_ip_range '10.0.0.1/24'
  etcd_servers 'http://127.0.0.1:2379'
  insecure_bind_address '0.0.0.0'
  action %w(create start)
end

group 'docker' do
  members %w(kubernetes)
end

kube_scheduler 'default' do
  master '127.0.0.1:8080'
  action %w(create start)
end

kube_controller_manager 'default' do
  master '127.0.0.1:8080'
  action %w(create start)
end

Here is my metadata.rb

depends 'etcd', '>= 6.0.0'
depends 'kube', '>= 4.0.0'
depends 'docker', '>= 7.0.0'

But after running the recipe I get the following error:

    ================================================================================
    virtualbox-iso: Recipe Compile Error in /var/chef/cache/cookbooks/k8_master/recipes/default.rb
    virtualbox-iso: ================================================================================
    virtualbox-iso:
    virtualbox-iso: NoMethodError
    virtualbox-iso: -------------
    virtualbox-iso: undefined method `kube_apiserver' for cookbook: k8_master, recipe: default :Chef::Recipe
    virtualbox-iso:
    virtualbox-iso: Cookbook Trace: (most recent call first)
    virtualbox-iso: ----------------------------------------
    virtualbox-iso:   /var/chef/cache/cookbooks/k8_master/recipes/default.rb:48:in `from_file'
    virtualbox-iso:
    virtualbox-iso: Relevant File Content:
    virtualbox-iso: ----------------------
    virtualbox-iso: /var/chef/cache/cookbooks/k8_master/recipes/default.rb:
    virtualbox-iso:
    virtualbox-iso:  46:  # Kubernetes cluster
    virtualbox-iso:  47:
    virtualbox-iso:  48>> kube_apiserver 'default' do
    virtualbox-iso:  49:    service_cluster_ip_range '10.0.0.1/24'
    virtualbox-iso:  50:    etcd_servers 'http://127.0.0.1:2379'
    virtualbox-iso:  51:    insecure_bind_address '0.0.0.0'
    virtualbox-iso:  52:    action %w(create start)
    virtualbox-iso:  53:  end
    virtualbox-iso: 
    virtualbox-iso: System Info:
    virtualbox-iso: ------------
    virtualbox-iso: chef_version=16.4.41
    virtualbox-iso: platform=centos
    virtualbox-iso: platform_version=7.8.2003
    virtualbox-iso: ruby=ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-linux]
    virtualbox-iso: program_name=/bin/chef-client
    virtualbox-iso: executable=/opt/chef/bin/chef-client
    virtualbox-iso:
    virtualbox-iso:

I followed exactly as specified in Readme Can someone tell me whats wrong here ?

-- Hassnain Alvi
chef-infra
kubernetes

1 Answer

9/14/2020

You need to use the v5.0.0 version of that cookbook which has support for Chef Infra Client 16:

https://github.com/aespinosa/cookbook-kube/commit/f95626f6ce00b9f8c9cf94fbcb87dfffb74d00c2

-- lamont
Source: StackOverflow