Skip to content

Instantly share code, notes, and snippets.

@mahkassem
Last active December 25, 2022 03:22
Show Gist options
  • Save mahkassem/0a6bafcb5210f3576a2100af0efb1922 to your computer and use it in GitHub Desktop.
Save mahkassem/0a6bafcb5210f3576a2100af0efb1922 to your computer and use it in GitHub Desktop.
k8s

K8s

kubeconfig

  • kubectl commands:
# View the current context:
kubectl config current-context

# View the current config:
kubectl config view

# Where to find the file:
cat ~/.kube/config
# OR
/etc/rancher/k3s/k3s.yaml

# Change config file:
kubectl --kubeconfig {path-to-file} {command}
  • Example of a kubeconfig file:
apiVersion: v1
# define the cluster metadata 
clusters:
- cluster:
    certificate-authority-data: {{ CA }}
    server: https://127.0.0.1:63668
  name: udacity-cluster
# define the user details 
users:
# `udacity-user` user authenticates using client and key certificates 
- name: udacity-user
  user:
    client-certificate-data: {{ CERT }}
    client-key-data: {{ KEY }}
# `green-user` user authenticates using a token
- name: green-user
  user:
    token: {{ TOKEN }}
# define the contexts 
contexts:
- context:
    cluster: udacity-cluster
    user: udacity-user
  name: udacity-context
# set the current context
current-context: udacity-context
  • kubectl commands:
# Inspect  the endpoints for the cluster and installed add-ons 
kubectl cluster-info

# List all the nodes in the cluster. 
# To get a more detailed view of the nodes, the `-o wide` flag can be passed
kubectl get nodes [-o wide] 

# Describe a cluster node.
# Typical configuration: node IP, capacity (CPU and memory), a list of running pods on the node, podCIDR, etc.
kubectl describe node {{ NODE NAME }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment