Top Related Projects
Production-Grade Container Scheduling and Management
Conformance test suite for OpenShift
Complete container management platform
The Kubernetes Package Manager
Declarative Continuous Deployment for Kubernetes
Terraform enables you to safely and predictably create, change, and improve infrastructure. It is a source-available tool that codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned.
Quick Overview
kubectl is the official command-line interface (CLI) for Kubernetes, an open-source container orchestration platform. It allows users to interact with Kubernetes clusters, deploy applications, inspect and manage cluster resources, and view logs. kubectl is an essential tool for developers and administrators working with Kubernetes environments.
Pros
- Comprehensive functionality for managing Kubernetes clusters
- Well-documented and widely supported by the Kubernetes community
- Consistent interface across different Kubernetes distributions
- Extensible through plugins and custom resource definitions
Cons
- Steep learning curve for beginners
- Command syntax can be verbose and complex for some operations
- Limited built-in visualization capabilities
- Performance can be slow for large-scale operations on big clusters
Code Examples
- Creating a deployment:
kubectl create deployment nginx --image=nginx
This command creates a new deployment named "nginx" using the nginx image.
- Scaling a deployment:
kubectl scale deployment nginx --replicas=3
This command scales the "nginx" deployment to 3 replicas.
- Getting pod information:
kubectl get pods -o wide
This command retrieves information about all pods in the current namespace, with additional details.
- Applying a configuration file:
kubectl apply -f my-config.yaml
This command applies the configuration defined in the "my-config.yaml" file to the cluster.
Getting Started
To get started with kubectl:
-
Install kubectl on your local machine:
- For macOS:
brew install kubectl
- For Linux:
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
- For Windows:
choco install kubernetes-cli
- For macOS:
-
Configure kubectl to connect to your Kubernetes cluster:
kubectl config set-cluster my-cluster --server=https://your-cluster-api-server kubectl config set-credentials my-user --token=your-user-token kubectl config set-context my-context --cluster=my-cluster --user=my-user kubectl config use-context my-context
-
Verify the connection:
kubectl cluster-info
Now you're ready to start using kubectl to manage your Kubernetes cluster!
Competitor Comparisons
Production-Grade Container Scheduling and Management
Pros of kubernetes
- More comprehensive, containing the entire Kubernetes project codebase
- Provides deeper access to Kubernetes internals and core functionality
- Allows for contributions to the entire Kubernetes ecosystem
Cons of kubernetes
- Larger codebase, potentially more complex to navigate and contribute to
- Requires more extensive knowledge of Kubernetes architecture
- May have a steeper learning curve for new contributors
Code Comparison
kubernetes:
// pkg/kubelet/kubelet.go
func (kl *Kubelet) syncPod(ctx context.Context, updateType kubetypes.SyncPodType, pod *v1.Pod, mirrorPod *v1.Pod, podStatus *kubecontainer.PodStatus) (isTerminal bool, err error) {
// ... (complex pod synchronization logic)
}
kubectl:
// pkg/cmd/run/run.go
func (o *RunOptions) Run() error {
// ... (simplified command execution logic)
}
The kubernetes repository contains more complex, low-level code for core Kubernetes functionality, while kubectl focuses on user-facing command-line interactions.
Conformance test suite for OpenShift
Pros of Origin
- Provides a more comprehensive platform with additional features like integrated CI/CD, built-in monitoring, and developer-focused tools
- Offers enhanced security features and compliance capabilities out-of-the-box
- Includes a web console for easier management and visualization of cluster resources
Cons of Origin
- Steeper learning curve due to additional complexity and features
- Less flexibility in terms of customization compared to the more lightweight kubectl
- Potentially higher resource requirements for running the full OpenShift platform
Code Comparison
Origin (OpenShift CLI):
oc new-app https://github.com/sclorg/cakephp-ex
oc expose service cakephp-ex
oc status
kubectl:
kubectl create deployment cakephp-ex --image=php:7.4-apache
kubectl expose deployment cakephp-ex --port=80
kubectl get all
The Origin CLI (oc) provides more abstracted commands for common operations, while kubectl offers more granular control over Kubernetes resources. Origin's CLI includes additional commands specific to OpenShift features, whereas kubectl focuses on core Kubernetes functionality.
Complete container management platform
Pros of Rancher
- Provides a user-friendly web interface for managing multiple Kubernetes clusters
- Offers built-in monitoring, logging, and alerting capabilities
- Simplifies cluster provisioning and management across different cloud providers
Cons of Rancher
- Adds an additional layer of complexity to the Kubernetes ecosystem
- May have a steeper learning curve for users already familiar with kubectl
- Requires additional resources to run the Rancher management server
Code Comparison
kubectl:
kubectl get pods -n kube-system
kubectl apply -f deployment.yaml
kubectl describe service my-service
Rancher:
# Example Rancher custom resource definition
apiVersion: management.cattle.io/v3
kind: Cluster
metadata:
name: my-cluster
spec:
dockerRootDir: /var/lib/docker
enableNetworkPolicy: false
While kubectl is a command-line tool for interacting directly with Kubernetes clusters, Rancher provides a more comprehensive management platform with additional features and abstractions. The code examples show the difference in approach, with kubectl using direct commands and Rancher utilizing custom resource definitions for cluster management.
The Kubernetes Package Manager
Pros of Helm
- Simplifies complex Kubernetes deployments with templating and package management
- Enables version control and rollback of entire application stacks
- Facilitates sharing and reuse of Kubernetes applications
Cons of Helm
- Steeper learning curve for new users compared to kubectl
- Potential security risks if using untrusted Helm charts
- Additional layer of abstraction may complicate troubleshooting
Code Comparison
Kubectl example:
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
Helm example (values.yaml):
replicaCount: 3
image:
repository: nginx
tag: 1.14.2
service:
type: ClusterIP
port: 80
Helm template:
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "mychart.fullname" . }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
app: {{ include "mychart.name" . }}
template:
metadata:
labels:
app: {{ include "mychart.name" . }}
spec:
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
ports:
- containerPort: {{ .Values.service.port }}
Declarative Continuous Deployment for Kubernetes
Pros of Argo CD
- Provides a declarative, GitOps-based approach to continuous delivery
- Offers a user-friendly web UI for visualizing and managing deployments
- Supports multi-cluster deployments and advanced rollback capabilities
Cons of Argo CD
- Requires additional setup and infrastructure compared to kubectl
- May have a steeper learning curve for teams new to GitOps practices
- Limited to Kubernetes-specific deployments, while kubectl is more versatile
Code Comparison
Argo CD (application manifest):
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: myapp
spec:
destination:
namespace: default
server: https://kubernetes.default.svc
project: default
source:
path: k8s
repoURL: https://github.com/example/myapp.git
targetRevision: HEAD
kubectl (deployment command):
kubectl apply -f deployment.yaml
Argo CD focuses on declarative, Git-based application definitions, while kubectl provides direct imperative commands for Kubernetes cluster management. Argo CD excels in automated, continuous delivery scenarios, whereas kubectl offers more flexibility for ad-hoc cluster operations and broader Kubernetes resource management.
Terraform enables you to safely and predictably create, change, and improve infrastructure. It is a source-available tool that codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned.
Pros of Terraform
- Supports multiple cloud providers and services, offering greater flexibility
- Declarative syntax allows for easier infrastructure versioning and collaboration
- Provides a more comprehensive approach to infrastructure as code (IaC)
Cons of Terraform
- Steeper learning curve for users new to IaC concepts
- May require additional setup and configuration for complex environments
- Limited native support for imperative operations compared to kubectl
Code Comparison
Terraform:
resource "aws_instance" "example" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = "t2.micro"
}
kubectl:
apiVersion: v1
kind: Pod
metadata:
name: example-pod
spec:
containers:
- name: example-container
image: nginx:latest
Terraform uses HCL (HashiCorp Configuration Language) to define resources, while kubectl typically uses YAML for Kubernetes manifests. Terraform's syntax is more focused on describing the desired state of infrastructure across various providers, whereas kubectl's YAML is specific to Kubernetes resource definitions.
Both tools serve different purposes: Terraform is primarily for provisioning and managing infrastructure, while kubectl is specifically for interacting with Kubernetes clusters. The choice between them depends on the scope of infrastructure management and the specific requirements of the project.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Kubectl
The k8s.io/kubectl
repo is used to track issues for the kubectl cli distributed
with k8s.io/kubernetes
. It also contains packages intended for use by client
programs. E.g. these packages are vendored into k8s.io/kubernetes
for use in
the kubectl
cli client. That client will eventually move here too.
Contribution Requirements
-
Full unit-test coverage.
-
Go tools compliant (
go get
,go test
, etc.). It needs to be vendorable somewhere else. -
No dependence on
k8s.io/kubernetes
. Dependence on other repositories is fine. -
Code must be usefully commented. Not only for developers on the project, but also for external users of these packages.
-
When reviewing PRs, you are encouraged to use Golang's code review comments page.
-
Packages in this repository should aspire to implement sensible, small interfaces and import a limited set of dependencies.
Community, discussion, contribution, and support
See this document for how to reach the maintainers of this project.
Code of conduct
Participation in the Kubernetes community is governed by the Kubernetes Code of Conduct.
Top Related Projects
Production-Grade Container Scheduling and Management
Conformance test suite for OpenShift
Complete container management platform
The Kubernetes Package Manager
Declarative Continuous Deployment for Kubernetes
Terraform enables you to safely and predictably create, change, and improve infrastructure. It is a source-available tool that codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot