curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
minikube start
kubectl cluster-info
kubectl get nodes
kubectl get all --all-namespaces
kubectl describe <resource_type> <resource_name>
Example:
kubectl describe pod my-pod
kubectl apply -f pod.yaml
kubectl get pods
kubectl describe pod <pod_name>
kubectl delete pod <pod_name>
kubectl exec -it <pod_name> -- <command>
Example:
kubectl exec -it my-pod -- /bin/bash
kubectl logs <pod_name>
kubectl create deployment <deployment_name> --image=<image_name>
kubectl get deployments
kubectl set image deployment/<deployment_name> <container_name>=<new_image>
kubectl scale deployment <deployment_name> --replicas=<number_of_replicas>
kubectl delete deployment <deployment_name>
kubectl expose deployment <deployment_name> --type=<service_type> --port=<port>
kubectl get services
kubectl describe service <service_name>
kubectl delete service <service_name>
kubectl create configmap <configmap_name> --from-file=<path_to_file>
kubectl create secret generic <secret_name> --from-literal=<key>=<value>
kubectl get configmaps
kubectl get secrets
kubectl create namespace <namespace_name>
kubectl get namespaces
kubectl config set-context --current --namespace=<namespace_name>
apiVersion: v1
kind: PersistentVolume
metadata:
name: my-pv
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
storageClassName: manual
nfs:
server: nfs-server.default.svc.cluster.local
path: "/path/to/data"
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: my-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
storageClassName: manual
kubectl get pv
kubectl get pvc
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: web
spec:
serviceName: "nginx"
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
kubectl get statefulsets
kubectl scale statefulset <statefulset_name> --replicas=<number_of_replicas>
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: fluentd-elasticsearch
namespace: kube-system
labels:
k8s-app: fluentd-logging
spec:
selector:
matchLabels:
name: fluentd-elasticsearch
template:
metadata:
labels:
name: fluentd-elasticsearch
spec:
containers:
- name: fluentd-elasticsearch
image: quay.io/fluentd_elasticsearch/fluentd:v2.5.2
kubectl get daemonsets
apiVersion: batch/v1
kind: Job
metadata:
name: pi
spec:
template:
spec:
containers:
- name: pi
image: perl
command: ["perl", "-Mbignum=bpi", "-wle", "print bpi(2000)"]
restartPolicy: Never
backoffLimit: 4
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: hello
spec:
schedule: "*/1 * * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: hello
image: busybox
args:
- /bin/sh
- -c
- date; echo Hello from the Kubernetes cluster
restartPolicy: OnFailure
kubectl get jobs
kubectl get cronjobs
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
namespace: default
name: pod-reader
rules:
- apiGroups: [""]
resources: ["pods"]
verbs: ["get", "watch", "list"]
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: read-pods
namespace: default
subjects:
- kind: User
name: jane
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: Role
name: pod-reader
apiGroup: rbac.authorization.k8s.io
kubectl get roles
kubectl get rolebindings
curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash
helm repo add stable https://charts.helm.sh/stable
helm search repo <chart_name>
helm install <release_name> <chart_name>
helm list
helm upgrade <release_name> <chart_name>
helm uninstall <release_name>
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm install prometheus prometheus-community/kube-prometheus-stack
kubectl port-forward deployment/prometheus-grafana 3000
kubectl apply -f https://raw.githubusercontent.com/elastic/cloud-on-k8s/master/config/samples/elasticsearch/elasticsearch.yaml
kubectl apply -f https://raw.githubusercontent.com/elastic/cloud-on-k8s/master/config/samples/kibana/kibana.yaml
kubectl apply -f https://raw.githubusercontent.com/elastic/cloud-on-k8s/master/config/samples/beats/filebeat_autodiscover.yaml
kubectl get pods
kubectl describe pod <pod_name>
kubectl logs <pod_name>
kubectl logs <pod_name> -c <container_name> # For multi-container pods
kubectl get nodes
kubectl describe node <node_name>
kubectl get events --sort-by=.metadata.creationTimestamp
kubectl top nodes
kubectl top pods
kubectl run -it --rm debug --image=busybox --restart=Never -- /bin/sh
kubectl port-forward <pod_name> <local_port>:<pod_port>
2024 © All rights reserved - buraxta.com