This is in continuation of Kubernetes article series. In the earlier posts, we have seen how to create & deploy a simple cluster. Now in this post, we are going to look at how to provision Kubernetes cluster using kops
utility. For more posts on Kubernetes, check out here & here.
kops (Kubernetes Operations) helps you create, destroy, upgrade and maintain production-grade, highly available, Kubernetes clusters from the command line. Some of the key features are listed below:
This quickstart assumes a basic understanding of Kubernetes concepts, please refer earlier posts for understanding on Kubernetes & how to create, deploy & rollout updates to the cluster.
Quick Snapshot
I’m using Linux so here are the commands to get kops
, for other releases/ platform you can find it here.
wget -O kops https://github.com/kubernetes/kops/releases/download/$(curl -s https://api.github.com/repos/kubernetes/kops/releases/latest | grep tag_name | cut -d '"' -f 4)/kops-linux-amd64
chmod +x ./kops
sudo mv ./kops /usr/local/bin/
Download the latest release with the command:
curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
Make the kubectl binary executable.
chmod +x ./kubectl
Move the binary in to your PATH.
sudo mv ./kubectl /usr/local/bin/kubectl
To check what are the available kubectl commands,run kubectl from the terminal
$ kubectl
kubectl controls the Kubernetes cluster manager.
Find more information at https://github.com/kubernetes/kubernetes.
Basic Commands (Beginner):
create Create a resource from a file or from stdin.
expose Take a replication controller, service, deployment or pod and
expose it as a new Kubernetes Service
run Run a particular image on the cluster
set Set specific features on objects
run-container Run a particular image on the cluster. This command is
deprecated, use "run" instead
Basic Commands (Intermediate):
get Display one or many resources
explain Documentation of resources
edit Edit a resource on the server
delete Delete resources by filenames, stdin, resources and names, or
by resources and label selector
Deploy Commands:
rollout Manage the rollout of a resource
rolling-update Perform a rolling update of the given ReplicationController
scale Set a new size for a Deployment, ReplicaSet, Replication
Controller, or Job
autoscale Auto-scale a Deployment, ReplicaSet, or ReplicationController
Cluster Management Commands:
certificate Modify certificate resources.
cluster-info Display cluster info
top Display Resource (CPU/Memory/Storage) usage.
cordon Mark node as unschedulable
uncordon Mark node as schedulable
drain Drain node in preparation for maintenance
taint Update the taints on one or more nodes
Troubleshooting and Debugging Commands:
describe Show details of a specific resource or group of resources
logs Print the logs for a container in a pod
attach Attach to a running container
exec Execute a command in a container
port-forward Forward one or more local ports to a pod
proxy Run a proxy to the Kubernetes API server
cp Copy files and directories to and from containers.
auth Inspect authorization
Advanced Commands:
apply Apply a configuration to a resource by filename or stdin
patch Update field(s) of a resource using strategic merge patch
replace Replace a resource by filename or stdin
convert Convert config files between different API versions
Settings Commands:
label Update the labels on a resource
annotate Update the annotations on a resource
completion Output shell completion code for the specified shell (bash or
zsh)
Other Commands:
api-versions Print the supported API versions on the server, in the form of
"group/version"
config Modify kubeconfig files
help Help about any command
plugin Runs a command-line plugin
version Print the client and server version information
Use "kubectl --help" for more information about a given command.
Use "kubectl options" for a list of global command-line options (applies to all
commands).
Login to AWS Console, In the navigation pane, choose Users and then choose Add user to create new user with Programmatic access. This is the user kops
would connect and store the cluster state information.
Alternatively, you can also create the IAM user from the command line using AWS CLI tools.
Set following IAM permissions for the kops user & click on Next
Review permissions & Click Next
User creation successful, record Access key ID
& Secret access key
. We would be using them in the next step.
Run the below commands to set the environment variables
export AWS_ACCESS_KEY_ID=<replace with your access key> export AWS_SECRET_ACCESS_KEY=<replace with your secret key>
In order to store the state of your cluster, and the representation of your cluster, we need to create a dedicated S3 bucket for kops
to use. This bucket will become the source of truth for our cluster configuration.
Enter bucket name & click Next,Enable Versioning for production environment if in case you ever need to revert or recover a previous state store.
To recap,we have installed kubectl,kops utilities,created new IAM user and s3 bucket to hold cluster information. We are now ready to create our 1st cluster.
Run the below commands to set the environment variables
export NAME=k8cluster.k8s.local <replace appropriately> export KOPS_STATE_STORE=s3://kubernetes-upnxt-aws-io <replace appropriately>
Here NAME
indicates the cluster name, make sure it ends with k8s.local and KOPS_STATE_STORE
is the s3 bucket location.
Next, step is to create cluster configuration. Make sure that you have generated SSH key pair before creating the cluster.
kops create cluster \
--zones us-west-2a \
${NAME}
Here zones
refers to which region/zone you would want to create the cluster. This is the basic example of creating cluster, more examples can be found here.
Once the cluster is created, you can use kubectl
to view and interact with the cluster. As you can see, the cluster has been created with 1 master & 1 worker node.
Congrats! our Kubernetes cluster is online and working.
Next, if you’re planning to deploy or update the application, you can follow the same set of steps as described in the earlier posts.
As a last step, if you want to delete the cluster that we created above use below command.
kops delete cluster --name ${NAME} --yes
Like this post? Don’t forget to share it!
There are few things as valuable to a business as well-designed software. Organizations today rely…
The cryptocurrency industry is being reshaped by the fusion of blockchain technology and artificial intelligence…
Introduction Artificial Intelligence (AI) has also found its relevance in graphic design and is quickly…
Imagine a world where the brilliance of Artificial Intelligence (AI) meets the unbreakable security of…
In today’s fast-paced digital landscape, automation is not just a luxury but a necessity for…
The world of casino gaming has leveraged the emerging technology advancements to create immersive and…
This website uses cookies.