🧪 Experiment: Installing Kubectl and Deploying Your
First Kubernetes Application
✅ Objective:
To install and configure kubectl, the Kubernetes command-line tool.
To use kubectl to interact with the cluster.
To deploy a sample Kubernetes application (nginx).
To validate its deployment using Kubernetes services.
🧰 Tools Required:
A working Kubernetes cluster (local using Minikube/kubeadm, or on cloud)
Ubuntu/Linux system or terminal (Windows WSL also works)
Internet access
User permissions to run kubectl
📚 Theory:
🔷 What is kubectl?
kubectl is a command-line tool that allows you to communicate with the Kubernetes
API server.
It helps in deploying, inspecting, and managing Kubernetes applications.
🔧 Part A: Install kubectl on Ubuntu/Linux
Step 1: Download the Latest kubectl Binary
curl -LO "https://dl.k8s.io/release/$(curl -L -s
https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
Step 2: Make Binary Executable
chmod +x kubectl
sudo mv kubectl /usr/local/bin/
🔽 Screenshot Placeholder: Kubectl Installed Successfully
Step 3: Verify Installation
kubectl version --client
🔽 Expected Output: Shows kubectl version details
🔧 Part B: Configure kubectl (If Not Done
Automatically)
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
🔽 Screenshot Placeholder: Config Setup for kubectl
🔧 Part C: Run kubectl Cluster Management
Commands
🔹 Check Cluster Nodes:
kubectl get nodes
🔹 Check Namespaces:
kubectl get namespaces
🔹 Get System Pods:
kubectl get pods -n kube-system
🔽 Screenshot Placeholder: kubectl get nodes and get pods output
Part D: Deploy Your First Kubernetes Application
Step 1: Run Nginx Application
kubectl create deployment my-nginx --image=nginx
Step 2: Verify Deployment
kubectl get deployments
kubectl get pods
Step 3: Expose Deployment as a Service
kubectl expose deployment my-nginx --type=NodePort --port=80
Step 4: Get Service Details
kubectl get svc
🔽 Expected Output: Shows service my-nginx with assigned NodePort
✅ Output:
A fully running nginx pod in Kubernetes.
Exposed to outside via NodePort.
Validated using kubectl get commands.
🌐 (Optional) Step: Access the Application
If using Minikube:
minikube service my-nginx
If on EC2 or kubeadm, use:
http://<Node-IP>:<NodePort>
📌 Conclusion:
You’ve successfully installed kubectl and used it to interact with your Kubernetes
cluster.
Deployed a sample nginx application and exposed it as a service.
Learned to inspect deployments, services, and pods using kubectl.