Coder Social home page Coder Social logo

k8s-admin-helper's Introduction

Kubernetes Admin Helper

This project contains selection of resources helpful for Kubernetes Administrators.

Manifests templates are created based on official Kubernetes Documentation and API Reference v1.9

Cheat sheet commands are based on official kubectl Cheat Sheet


Autocompletion

source <(kubectl completion bash)

Configuration and Maintenance

kubectl config view
kubectl config current-context
kubectl config use-context CONTEXT

kubectl cluster-info
kubectl get componentstatuses
kubectl get events

# Logs
kubectl logs --namespace=NAMESPACE POD_NAME --container=CONTAINER_NAME
kubectl logs --previous POD_NAME --container=CONTAINER_NAME

# Namespaces
kubectl get namespace
kubectl create namespace NAMESPACE

Resource lifecycle operations

Create

kubectl create -f my-manifest.yaml            # create from file
kubectl create -f my1.yaml -f my2.yaml        # create from multiple files
kubectl create -f dir                         # create from files in dir

Read

kubectl get pods                              # List all pods in the namespace
kubectl get pods --all-namespaces             # List all pods in all namespaces
kubectl get pods -o wide                      # List all pods in the namespace, with more details
kubectl get pods --include-uninitialized      # List all pods in the namespace, including uninitialized ones
kubectl get pods --watch                      # List all pods and watch changes
kubectl get pod my-pod                        # List a particular deployment

kubectl describe nodes my-node

kubectl get services --sort-by=.metadata.name # List Services Sorted by Name

# List pods Sorted by Restart Count
kubectl get pods --sort-by='.status.containerStatuses[0].restartCount'

# Get the version label of all pods with label app=cassandra
kubectl get pods --selector=app=cassandra -o jsonpath='{.items[*].metadata.labels.version}'

# Get all running pods in the namespace
kubectl get pods --field-selector=status.phase=Running

# Get ExternalIPs of all nodes
kubectl get nodes -o jsonpath='{.items[*].status.addresses[?(@.type=="ExternalIP")].address}'

# List Names of Pods that belong to Particular Deployment
# "jq" command useful for transformations that are too complex for jsonpath, it can be found at https://stedolan.github.io/jq/
sel=$(kubectl get deployment nginx-deployment -o=json | jq -j '.spec.selector.matchLabels | to_entries | map([.key,.value] | join("=")) | join(",")')
kubectl get pods -l=$sel -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}'

Update

# Force replace, delete and then re-create the resource. Will cause a service outage.
kubectl replace --force -f ./pod.json

Node

kubectl label node NODE KEY=VALUE

kubectl get nodes --show-labels

kubectl get nodes -o jsonpath="{$.items[*].metadata.labels}"

# Taint
kubectl taint node NODE_NAME LABEL_KEY=LABEL_VALUE:NoSchedule


# Drain and Uncordon
kubectl drain NODE_NAME
kubectl uncordon NODE_NAME

etcd

GitHub:

Global flags

# API version
export ETCDCTL_API=3

# Certificates
export ETCDCTL_CACERT=/tmp/ca.pem
export ETCDCTL_CERT=/tmp/cert.pem
export ETCDCTL_KEY=/tmp/key.pem

Commands

# List etcd cluster members
etcdctl member list

# List resources
etcdctl ls
etcdctl ls /registry

# Backup
etcdctl --endpoints <ENDPOINT> snapshot save snapshotdb
etcdctl --write-out=table snapshot status snapshotdb

systemd

systemctl list-units | grep kube

systemctl status kube-apiserver

journalctl -u kubelet

Minikube

minikube start
minikube ip
minikube version
minikube ssh

containerd

sudo ctr -n k8s.io containers list

k8s-admin-helper's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.