Làm thế nào để gõ kubectl trên máy của mình mà connect đến master k8s
đầu tiền cần cài kubectl
https://kubernetes.io/docs/tasks/tools/
Tiếp theo
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
$HOME chính là được dẫn folder home của máy bạn

Có những trường hợp các bạn gõ kubectl nhưng hiện thị lỗi là connection timeout thì cat file config và kiểm tra dòng server
server: https://192.168.101.40:6443
thực hiển lệnh curl
root@spinnaker-ubuntu16:~# curl -v telnet://192.168.101.40:6443
* Rebuilt URL to: telnet://192.168.101.40:6443/
* Trying 192.168.101.40...
* Connected to 192.168.101.40 (192.168.101.40) port 6443 (#0)
phải connected thì máy bạn mới connect với k8s master nhé
netstat -ntlp
show các port tại máy mà bạn muốn show.
Writing a few helpful command kubectl
Hướng dẫn exec vào container:
kubectl exec -it -n default <pod_name> -c <container_name> -- bash
>>>>
kubectl exec -it -n default spinnaker-halyard-7787d9479d-hrqp8 -c spinnaker-halyard -- bash
kubectl exec -i -t busybox-deployment-57c9d48f54-jrwmc -c busybox -- sh -c "clear; (bash || ash || sh)"
Hướng dẫn copy 1 file từ conntainer ra local
kubectl cp <namespace>/<pod_name>:<folder_source> <folder_destination> -c <container>
>>>>
kubectl cp default/spinnaker-halyard-7787d9479d-hrqp8:/home/spinnaker/ /root/spinnaker -c spinnaker-halyard
Get secret registry
kubectl -n platform get secret --context dev
kubectl -n platform get secret/nimtechnology-gcr --context dev -o yaml
Delete evict pods
kubectl get pod -n nimtechnology | grep Evicted | awk '{print $1}' | xargs kubectl delete pod -n nimtechnology
cordon and drain node with kubectl
Drain node: This will mark the node as unschedulable and also evict pods on the node.
Cordon node: Mark node as unschedulable.
kubectl cordon <node_name>
kubectl cordon ip-10-195-228-109.us-west-2.compute.internal
kubectl drain <node_name> --delete-local-data --ignore-daemonsets --force
kubectl drain ip-10-195-228-37.us-west-2.compute.internal --delete-local-data --ignore-daemonsets --force
Create secret from file
kubectl create secret generic multi-aws-credentials \
-n argocd \
--from-file=.aws/config \
--from-file=.aws/credentials
Deployment is used test(curl)
apiVersion: apps/v1 kind: Deployment metadata: name: busybox-deployment labels: app: busybox spec: replicas: 1 strategy: type: RollingUpdate selector: matchLabels: app: busybox template: metadata: labels: app: busybox spec: nodeSelector: kubernetes.io/os: linux containers: - name: busybox image: yauritux/busybox-curl imagePullPolicy: IfNotPresent command: ['sh', '-c', 'echo Container 1 is Running ; sleep 3600']
Delete the specific deployment on k8s
ENGINES_IS_KEPT=( <name_deployment_A> <name_deployment_B> ) kubectl get deployment -n <name_space> | grep <grep_name> | awk '{print $1}' > tmp.txt file="./tmp.txt" while read line; do echo "I found out -> ${line}" if ! [[ ${ENGINES_IS_KEPT[*]} =~ "$line" ]]; then kubectl -n <name_space> delete deployment/$line fi done < "${file}"
Delete the pod to be evicted
kubectl get pod -n <name_space> | grep Evicted | awk '{print $1}' | xargs kubectl delete pod -n <name_space>
It is the best time to make a few plans for the
future and it is time to be happy. I have learn this post
and if I could I want to suggest you few attention-grabbing things or suggestions.
Perhaps you could write subsequent articles regarding this
article. I wish to learn more things approximately it!
My brother suggested I might like this website. He was entirely right.
This post actually made my day. You can not imagine just
how much time I had spent for this info! Thanks!
thank you for watching my post