Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ../../../base-application/checkout
- ../../../../base-application/checkout
patches:
- path: deployment.yaml
12 changes: 12 additions & 0 deletions website/docs/introduction/basics/access/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
title: Cluster Access
sidebar_position: 20
description: "Learn how to configure access and interact with Kubernetes clusters using kubeconfig and kubectl."
---

# Interacting with Kubernetes

Now that you understand what Kubernetes is, let's learn **how to interact with it** using the command-line tool and cluster configuration.

- [kubectl](./kubectl) - The command-line tool for managing Kubernetes resources and applications.
- [kubeconfig](./kubeconfig) - A `YAML` file holds the information needed to interact with Kubernetes API Server.
205 changes: 205 additions & 0 deletions website/docs/introduction/basics/access/kubeconfig.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
---
title: kubeconfig
sidebar_position: 20
description: "Learn how to configure access to Kubernetes clusters using kubeconfig and AWS EKS integration."
---

# Cluster Access & Configuration

To use kubectl with a Kubernetes cluster, you need to configure access using a **kubeconfig** file.

The kubeconfig file is a YAML configuration file that tells kubectl:
- **Where** to find your Kubernetes cluster (API server endpoint)
- **How** to authenticate with it (credentials)
- **Which** cluster and user to use by default (context)

### kubeconfig Structure

A kubeconfig file contains three main sections:

```yaml
apiVersion: v1
kind: Config
clusters: # Information about Kubernetes clusters
- name: my-cluster
cluster:
server: https://kubernetes-api-server:6443
certificate-authority-data: <base64-encoded-ca-cert>

users: # Authentication credentials for different users
- name: my-user
user:
token: <authentication-token>
# OR client-certificate-data and client-key-data
# OR exec command for dynamic authentication

contexts: # Combinations of cluster + user + namespace
- name: my-context
context:
cluster: my-cluster
user: my-user
namespace: default

current-context: my-context # Which context to use by default
```

### Key Components Explained

**Clusters**: Define how to connect to Kubernetes API servers
- **server**: The API server URL (e.g., `https://my-cluster.example.com:6443`)
- **certificate-authority**: CA certificate to verify the server's identity
- **insecure-skip-tls-verify**: Skip TLS verification (not recommended for production)

**Users**: Define authentication methods
- **token**: Bearer token authentication
- **client-certificate/client-key**: Mutual TLS authentication
- **username/password**: Basic authentication (rarely used)
- **exec**: External command for dynamic authentication (like AWS CLI)

**Contexts**: Combine cluster + user + optional default namespace
- Allows you to easily switch between different clusters or users
- Can set a default namespace to avoid specifying `-n` repeatedly

### Managing Multiple Clusters

kubeconfig supports multiple clusters, users, and contexts in a single file:

```bash
# View your complete kubeconfig
$ kubectl config view

# List all available contexts
$ kubectl config get-contexts

# Check current context
$ kubectl config current-context
```

Additional commands:
```
# Switch between contexts
$ kubectl config use-context <context-name>

# Set default namespace for current context
$ kubectl config set-context --current --namespace=<namespace>
```

### kubeconfig File Location

By default, kubectl looks for kubeconfig at:
- `~/.kube/config` (Linux/macOS)
- `%USERPROFILE%\.kube\config` (Windows)

You can override this with:
- `KUBECONFIG` environment variable
- `--kubeconfig` flag with kubectl commands

## EKS-Specific Configuration

Amazon EKS integrates seamlessly with the standard kubeconfig pattern but adds AWS-specific authentication.

### AWS CLI Integration

For EKS clusters, AWS CLI provides a convenient way to configure kubectl:

```bash
# Configure kubectl for your EKS cluster
$ aws eks update-kubeconfig --region us-west-2 --name eks-workshop

# Verify the connection
$ kubectl get nodes
```

### What AWS CLI Does

When you run `aws eks update-kubeconfig`, it:

1. **Retrieves cluster information** from the EKS API
2. **Updates your kubeconfig file** (`~/.kube/config`)
3. **Sets up AWS authentication** using the `aws eks get-token` command

### EKS kubeconfig Structure

Here's what an EKS entry looks like in your kubeconfig:

```yaml
clusters:
- cluster:
certificate-authority-data: <base64-ca-cert>
server: https://ABC123.gr7.us-west-2.eks.amazonaws.com
name: arn:aws:eks:us-west-2:123456789012:cluster/eks-workshop

users:
- name: arn:aws:eks:us-west-2:123456789012:cluster/eks-workshop
user:
exec:
apiVersion: client.authentication.k8s.io/v1beta1
command: aws
args:
- eks
- get-token
- --cluster-name
- eks-workshop
- --region
- us-west-2

contexts:
- context:
cluster: arn:aws:eks:us-west-2:123456789012:cluster/eks-workshop
user: arn:aws:eks:us-west-2:123456789012:cluster/eks-workshop
name: arn:aws:eks:us-west-2:123456789012:cluster/eks-workshop
```

### EKS Authentication Flow

When you run kubectl commands with EKS:

1. **kubectl** reads the kubeconfig file
2. **Executes** `aws eks get-token` command
3. **AWS CLI** uses your AWS credentials to get a temporary token
4. **kubectl** uses this token to authenticate with the EKS API server
5. **EKS** validates the token and maps it to Kubernetes RBAC permissions

### AWS Credentials for EKS

EKS authentication relies on your AWS credentials, which can come from:
- **AWS CLI profiles** (`~/.aws/credentials`)
- **Environment variables** (`AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`)
- **IAM roles** (EC2 instance profiles, EKS service accounts)
- **AWS SSO** sessions

### Viewing Your EKS Configuration

```bash
# See your current kubeconfig (including EKS entries)
$ kubectl config view

# Check which EKS cluster you're connected to
$ kubectl config current-context

# Test your connection
$ kubectl get nodes

# Get cluster information
$ kubectl cluster-info
```

## Key Concepts to Remember

### kubeconfig Fundamentals
- **kubeconfig file** is the standard way Kubernetes stores cluster connection information
- **Three main components**: clusters (where), users (who), contexts (which combination)
- **Works the same** across all Kubernetes distributions (EKS, GKE, AKS, self-managed)
- **File location**: `~/.kube/config` by default, customizable via `KUBECONFIG` environment variable

### EKS Integration
- **AWS CLI integration** uses standard kubeconfig with AWS-specific authentication via `aws eks get-token`
- **Dynamic authentication** - tokens are generated on-demand using your AWS credentials
- **No static credentials** stored in kubeconfig - more secure than traditional approaches

### Context Management
- **Contexts** combine cluster + user + optional namespace for easy switching
- **Multiple clusters** can be managed from a single kubeconfig file
- **Default namespace** can be set per context to avoid repetitive `-n` flags

Now that you understand how kubectl connects to clusters, let's explore the core Kubernetes resources, starting with [Namespaces](../../namespaces) for organizing your resources, then [Pods](../../pods) - the smallest deployable units in Kubernetes.
139 changes: 139 additions & 0 deletions website/docs/introduction/basics/access/kubectl.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
---
title: kubectl
sidebar_position: 10
description: "Learn essential kubectl commands for managing Kubernetes resources."
---

[kubectl](https://kubernetes.io/docs/reference/kubectl/) (pronounced "kube-control" or "kube-c-t-l") is the command-line tool that communicates with the Kubernetes API server. It translates your commands into API calls and presents the results in a human-readable format.

All kubectl commands follow this pattern:
```
kubectl [command] [type] [name] [flags]
```

Examples:
- `kubectl get pods` - List all pods
- `kubectl describe service ui` - Get detailed info about the ui service
- `kubectl apply -f deployment.yaml` - Create resources from a file

kubectl has excellent built-in documentation. Let's explore it:

```bash
$ kubectl
kubectl controls the Kubernetes cluster manager.

Find more information at: https://kubernetes.io/docs/reference/kubectl/

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

Basic Commands (Intermediate):
explain Get documentation for a resource
get Display one or many resources
edit Edit a resource on the server
delete Delete resources by file names, stdin, resources and names, or by resources and
label selector

Deploy Commands:
rollout Manage the rollout of a resource
scale Set a new size for a deployment, replica set, or replication controller
autoscale Auto-scale a deployment, replica set, stateful set, or replication controller

Cluster Management Commands:
certificate Modify certificate resources
cluster-info Display cluster information
top Display resource (CPU/memory) 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
debug Create debugging sessions for troubleshooting workloads and nodes
events List events

Advanced Commands:
diff Diff the live version against a would-be applied version
apply Apply a configuration to a resource by file name or stdin
patch Update fields of a resource
replace Replace a resource by file name or stdin
wait Experimental: Wait for a specific condition on one or many resources
kustomize Build a kustomization target from a directory or URL

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, zsh, fish, or
powershell)

Subcommands provided by plugins:
connect The command connect is a plugin installed by the user

Other Commands:
api-resources Print the supported API resources on the server
api-versions Print the supported API versions on the server, in the form of "group/version"
config Modify kubeconfig files
plugin Provides utilities for interacting with plugins
version Print the client and server version information

Usage:
kubectl [flags] [options]

Use "kubectl <command> --help" for more information about a given command.
Use "kubectl options" for a list of global command-line options (applies to all commands).
```

`kubectl` organizes commands into logical categories. Understanding these categories helps you find the right command for any task.
1. Basic Commands (Beginner & Intermediate)
2. Deploy Commands
3. Cluster Management Commands
4. Troubleshooting and Debugging Commands
5. Advanced Commands
6. Settings Commands
7. Other Commands

### Getting Help
kubectl has excellent built-in help:
```bash
# See all command categories
$ kubectl --help

# Get help for specific commands
$ kubectl get --help
$ kubectl apply --help

# Get resource documentation
$ kubectl explain pod
$ kubectl explain deployment.spec.template
```

## Workshop Patterns

Throughout this workshop, you'll frequently use these kubectl commands:

- `kubectl apply -k` for Kustomize deployments
- `kubectl get pods -n <namespace>` for checking application status
- `kubectl describe` and `kubectl logs` for troubleshooting
- `kubectl port-forward` for accessing applications locally

## Key Concepts to Remember

- **Command pattern**: `kubectl [command] [type] [name] [flags]` - all commands follow this structure
- **Get help**: Use `kubectl --help` or `kubectl <command> --help` to discover options
- **Declarative approach**: Use `kubectl apply -f` for production deployments
- **Namespace awareness**: Always specify `-n <namespace>` or use `-A` for all namespaces
- **Essential commands**: `get`, `describe`, `logs`, `apply`, `port-forward` cover most daily tasks

Now that you understand kubectl commands, you can learn more about [how kubectl connects to clusters](../cluster-access), or jump ahead to explore the core Kubernetes resources, starting with [Namespaces](../../namespaces) for organizing your resources.
Loading