40
Prerequisites
- Install the required tools:
- kubectl (Kubernetes command-line tool)
- doctl (Digital Ocean command-line tool)
Step 1: Configure Digital Ocean Access
# Install doctl if you haven't already
brew install doctl # For MacOS
# Or download from Digital Ocean website for other OS
# Authenticate with Digital Ocean
doctl auth init
# Enter your API token when prompted
BashStep 2: Connect to Your Cluster
# List all kubernetes clusters
doctl kubernetes cluster list
# Download cluster configuration
doctl kubernetes cluster kubeconfig save <cluster-name>
BashStep 3: Verify Connection
# Test connection by getting cluster info
kubectl cluster-info
# View all nodes
kubectl get nodes
# View all pods
kubectl get pods --all-namespaces
BashStep 4: Accessing Resources
Connect to a Pod:
# List pods in default namespace
kubectl get pods
# List pods in specific namespace
kubectl get pods -n <namespace>
# Connect to a specific pod
kubectl exec -it <pod-name> -- /bin/bash
# Or for a specific container in a pod:
kubectl exec -it <pod-name> -c <container-name> -- /bin/bash
BashView Pod Logs:
# View pod logs
kubectl logs <pod-name>
# Follow pod logs in real-time
kubectl logs -f <pod-name>
BashPort Forwarding:
# Forward local port to pod port
kubectl port-forward <pod-name> 8080:80
BashStep 5: Namespace Operations
# List all namespaces
kubectl get namespaces
# Set default namespace
kubectl config set-context --current --namespace=<namespace>
BashCommon Troubleshooting Commands
Check Pod Status:
# Get detailed pod information
kubectl describe pod <pod-name>
# Get pod status with wide output
kubectl get pods -o wide
BashCheck Node Status:
# Get detailed node information
kubectl describe node <node-name>
# Check node resources
kubectl top node
BashCheck Cluster Health:
# View cluster events
kubectl get events --sort-by='.metadata.creationTimestamp'
# Check component status
kubectl get componentstatuses
BashSecurity Note:
- Always use RBAC (Role-Based Access Control) to manage access
- Regularly rotate your Digital Ocean API tokens
- Be cautious when executing commands in production environments
- Consider using network policies to restrict pod-to-pod communication