Table of contents
1.
Introduction
2.
What is Upgrade Lab
3.
Requirements
3.1.
System Architecture Requirements
3.2.
Software Requirements
3.3.
Server Backup
3.4.
Infrastructure Requirements
3.4.1.
Credentials
3.4.2.
Connectivity
3.4.3.
Convergence
3.4.4.
Cookbook CI/CD
4.
Upgrade Lab
4.1.
Inventory
4.1.1.
Chef Report Nodes Command
4.1.2.
Chef Report Cookbooks Command
4.2.
Create an Upgrade Environment with Chef Capture
4.2.1.
Add Cookbook Source Locations
4.2.2.
Cookbook Directory Layout
4.2.3.
Main Cookbook Development Location
4.3.
Download Cookbooks from Chef Infra Server
5.
Deploying Chef Lab Upgrades
5.1.
Committing Cookbook Upgrades
5.2.
Optionally Uploading Cookbook Upgrades to the New Server
5.3.
Upload Supplemental Data to the New Server
5.3.1.
Node Data
5.3.2.
Roles
5.3.3.
Environments
5.3.4.
Data Bags
6.
Attach the Upgraded Node to the New Server
6.1.
Issuing a new Bootstrap Command
7.
Frequently Asked Questions
7.1.
What exactly is a chef infra server?
7.2.
What is the purpose of the chef client?
7.3.
Is Chef used in DevOps?
8.
Conclusion
Last Updated: Mar 27, 2024

About Upgrade Lab

Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

The best thing to know before cooking something is to know where to start from. When we are making a plan to cook, there are many little ingredients and utensils that we need to see and start our preparation. Upgrade lab kind of does a similar thing that lets us get a smooth start. Let us find out about Upgrade Lab today.

About Upgrade Lab

What is Upgrade Lab

The Upgrade Lab generates a summary of the existing nodes and cookbooks, allowing users to determine the scale of the work and a good place to begin. Upgrade Lab captures any node from the production environment and reproduces it locally by creating a repository for that node. This gives users a sandbox to work through updating and testing the cookbooks away from the production environment.

Requirements

Like every laboratory, Upgrade Lab also has some requirements. Let us look at them divided into different segments.

System Architecture Requirements

The Chef Upgrade Lab makes the following assumptions about our current system:

a. It assumes that our system has two Chef Infra Servers

1. A Chef Infra Server that is running an older version

2. A freshly installed Chef Infra Server with the most recent software. That has been set up and configured for knife but otherwise empty.

b. It assumes that the system has one or more nodes.

1. That has Chef Infra Client 12 or later running.

2. That has a minimum of 512 Megabytes of RAM.

3. It has the Recommended storage space of 5 Gigabytes.

4. It has been Bootstrapped to the older Chef Infra Server.

5. There are sudo permissions on the node.

6. It has Connectivity through SSH between nodes and the administrator/developer workstation. 

Software Requirements

  • We should examine the Chef Workstation platform and review the system requirements.
  • We should also Install or upgrade to the most recent version of the Chef Workstation.

Chef does not actually recommend or tell us to go for any particular editor. The Chef Infra extension for Visual Studio Code, on the other hand, has various code generators and useful functions, such as executing Cookstyle every time the user saves a recipe.

Server Backup

Before beginning any server update procedure, it is recommended to keep a backup.

Infrastructure Requirements

Let us have a look at the infrastructure requirements now.

Credentials

Knife profiles are used to set up user credentials. This solution keeps the keys in a credentials file and simplifies switching between credentials. Thus making it easy.

As we can see below, in .chef/credentials:

[old-server]
client_name = "here_we_add_the_username"
chef_server_url = "The_old_server_key_goes_here = """
-----BEGIN RSA PRIVATE KEY-----
MMM+Here+we+add+the+key+MMM
-----END RSA PRIVATE KEY-----
"""
[new-server]
client_name = "here_we_add_the_username"
chef_server_url = "The_new_server_url_goes_here = """
-----BEGIN RSA PRIVATE KEY-----
MMM+Here+we+add+the+key+MMM
-----END RSA PRIVATE KEY-----
""" 

Connectivity

So, now must have a user key for both Chef Infra Servers and be able to connect to them both from our development workstation.

Run a knife command to ensure connectivity and receive a suitable answer from each server.

chef exec knife user list --profile old-server
user_name
chef exec knife user list --profile new-server
user_name 

Convergence

We must ensure that all of our nodes are operational. Under the previous version of Chef Infra Client, they converge smoothly.

We may check the nodes' health by running this command:

chef exec knife status --profile old-server

This command returns the time of each node's most recent Chef Infra Client run that was successful. Nodes that return drastically different times for the most recent successful Chef Infra Client run are not functioning properly and are out of order.

We should get an output like the one below:

39 minutes ago, node-01, ubuntu 22.04.1

Cookbook CI/CD

Although a specific technology or process is not recommended, the Chef Upgrade Lab expects cookbook deployments to use a continuous integration pipeline. It also expects a continuous delivery system (CI/CD).

The Upgrade Lab expects but does not need that we have a continuous integration pipeline (CI) for your recipes that includes:

  • Version control software (for example, git)
  • Some automated testing for suggested changes is required.
  • A cookbook release control system (CD); the CD is the mechanism for upgrading cookbook versions and uploading them to the Chef Infra Server (s) 

Upgrade Lab

After going through the long list of requirements, let us find out about the Upgrade lab. We will see different parts of it below.

Inventory

Starting the upgrading process on a node with a simple setup is recommended. This can be the one with fewer and simpler cookbooks. Chef report searches our nodes and cookbooks and uses the reports to find out a nice place to start.

Chef Report Nodes Command

We should know that the chef report nodes -p PROFILE command will do the following:

  • It will build a report on our system's nodes by using Ohai data.
  • The command will print a summary of the report to the screen.
  • It will also save the report to the chef-workstation/reports/. This is the default directory.

We can run the command "chef report nodes -p old-server" from our development workstation. This will give us a node report. 

Chef Report Cookbooks Command

Now let us see what this command will do. 

We should know that the 

chef report cookbooks -p PROFILE 

command will do the following:

  • It will build a report on our system's cookbooks by using Ohai data.
  • The command will print a summary of the report to the screen.
  • It will also save the report to the chef-workstation/reports/. This is the default directory.

We can run the command

chef report cookbooks -V -p old-server

 from our development workstation. This will give us a node report.

Create an Upgrade Environment with Chef Capture

The chef capture NODE command will do the following:

  • Make a repository in the current directory for that node.
  • Assist us in obtaining and organising the cookbooks that are required to converge the node.
  • Create a kitchen.yml file. This file will allow us to use Test Kitchen for local development.

Add Cookbook Source Locations

Chef capture NODE asks us to fetch the cookbooks from their original locations after we create the repo.

Upgrading a node implies upgrading its cookbooks. This is for it to run the most recent version of Chef Infra Client. Ideally, we should obtain the cookbooks from their original source. That is git clone or another similar version control operation. If we are using a version control system, we can create and test changes locally before pushing them back to the cookbook's source. By allowing the changes to go through appropriate version control, peer review, automated testing, and automated deployment, we fully reap the benefits of the cookbook CI/CD pipeline.

If you can't find a cookbook, we should not download it from somewhere else, like the public Chef Supermarket. The version of the cookbook in our development environment must be the same as our node version. As a last option, during the capture step, the Upgrade Lab can get copies of the recipes via the Chef Infra Server.

These are common cookbook locations:

  • It has been checked into our version control system.
  • It is on a private Supermarket installation.
  • It is in an existing cookbook development directory.

Cookbook Directory Layout

Cookbooks can be stored in a single parent directory when we have access to cookbook sources.

The Upgrade Lab works when we have cookbooks in multiple locations, but it requires additional command-line prompts.

Main Cookbook Development Location

The chef capture command asks us for the primary cookbook source location first.

Suppose all cookbooks are not there in the same base location. In that case, we will be given the chance to give additional locations.
At this stage, at the prompt, we will enter the location of the cookbook development directory. For example, /Users/user_name/my_cookbooks.

chef capture command searches that path for the cookbooks it requires. The command is complete once it has accounted for all cookbook sources. But, if any still need to be included, it will prompt them in upcoming steps.

Download Cookbooks from Chef Infra Server

If users don't have access to a cookbook's original version-controlled source, we can press return at the chef capture prompt to utilise a copy obtained from the Chef Infra Server.

It is not a good idea to upgrade cookbooks from the Chef Infra Server. During the update, we will be making changes to the cookbooks. Making updates to the cookbooks without the ability to track those changes in version control nearly always results in cookbook source conflicts. Cookbooks with untracked changes are difficult to reconcile. If users find themselves using a lot of cookbooks—especially sophisticated cookbooks—downloaded from the Chef Infra Server, it will be worthwhile to try to identify their version-controlled sources in the long term.

Deploying Chef Lab Upgrades

Now we will see the process of moving upgraded cookbooks and nodes to a new Chef Infra Server. This pattern is only available to some. Particularly those who rely on chef search for inventory and coordination. Users that do not reliant on search will benefit from migrating to a new server. This is because it gives a fresh start for future migration to Effortless.

If users rely on knife search or cannot set up a new Chef Infra Server, upload the upgraded cookbooks to the current Chef Infra Server. If users do this, they should be sure to pin their cookbook versions to existing nodes. This is so that the upgraded cookbook may be promoted manually to targeted nodes.

Committing Cookbook Upgrades

Users should follow their organisation's established software development practices when making changes to the recipes. Commit any modifications to the cookbooks and send them to the cookbook pipeline to be tested by the automated testing system. Once the changes have been tested, the cookbooks should be given new version numbers and published to the new Chef Infra Server via the continuous deployment mechanism.

Optionally Uploading Cookbook Upgrades to the New Server

Users can directly upload the recipes to the new server. This is if their organisation does not have a cookbook pipeline in place or if they are building up a proof of concept. However, it is not suggested. This is because it makes managing changes to cookbook code difficult. As this command does not support embedded keys in credentials files, the key must be placed in a key file.

cd node-node-01-repo
chef exec knife upload cookbooks --chef-repo-path . --profile new-server --key ../keys/my-new-key.pem

Upload Supplemental Data to the New Server

After this, we have to upload the remaining data to the new server. It should be noted that the knife upload command does not permit embedded keys in credentials files, so the key must be placed in a key file.

Node Data

Upload the node data to the new server if you were using node search:

chef exec knife upload nodes --chef-repo-path . --profile new-server --key ../keys/my-new-key.pem

Roles

Upload the following roles to the new server if you were them:

chef exec knife upload roles --chef-repo-path . --profile new-server --key ../keys/my-new-key.pem

Environments

Upload the following environments to the new server if you are using them:

chef exec knife upload environments --chef-repo-path . --profile new-server --key ../keys/my-new-key.pem

Data Bags

Upload your data bags to the new server if you used them:

chef exec knife upload data_bags --chef-repo-path . --profile new-server --key ../keys/my-new-key.pem

Attach the Upgraded Node to the New Server

It is now time to Attach the Upgraded Node to the New Server. We will read about issuing a new Bootstrap Command.

Issuing a new Bootstrap Command

Run a bootstrap command similar to this one to migrate the node to the new server:

chef exec knife bootstrap \
    --profile new-server --chef-license accept \
    -r cookbook::recipe,another_cookbook::recipe \
    -N node-01 -y --sudo \
    --bootstrap-version 16 \
    user@somehost.example

By bootstrapping nodes in this manner, the installed Chef Infra Client is upgraded to version 16. 

As an option, users can erase their node record from the old server by using the following command:

chef exec knife node delete node-01 --profile old-server

Frequently Asked Questions

What exactly is a chef infra server?

Chef Infra Server is a configuration data hub. It stores node policies, cookbooks, and managed node metadata.

What is the purpose of the chef client?

A chef-client is an agent that runs locally on each node managed by Chef. When a chef-client is executed, it will complete all of the procedures needed to bring the node into the anticipated state. This includes: registering and authenticating the node with the Chef server.

Is Chef used in DevOps?

Yes, of course. It is one of the biggest among the DevOps tools. The big four DevOps tools include Ansible, Puppet, Salt and Chef.

Conclusion

In the article, we read about Upgrade Lab. We saw the requirements and read about deploying Chef Lab upgrades and uploading processes.  Refer to our courses and explore Coding Ninjas Studio to find more exciting stuff. You can also look into the interview experiences and solve different problems. Look into our Guided paths, test series, libraries and resources to know more.

Thank You

Happy Coding!

Live masterclass