Skip to content

NimTechnology

Trình bày các công nghệ CLOUD một cách dễ hiểu.

  • Kubernetes & Container
    • Docker
    • Kubernetes
      • Ingress
    • Helm Chart
    • Isito-EnvoyFilter
    • Apache Kafka
      • Kafka
      • Kafka Connect
      • Lenses
    • Vault
    • Longhorn – Storage
    • VictoriaMetrics
    • MetalLB
    • Kong Gateway
  • CI/CD
    • ArgoCD
    • ArgoWorkflows
    • Spinnaker
    • Jenkins
    • Harbor
    • TeamCity
    • Git
      • Bitbucket
  • Coding
    • Terraform
      • GCP – Google Cloud
      • AWS – Amazon Web Service
    • Golang
    • Laravel
    • Python
    • Jquery & JavaScript
    • Selenium
  • Log & Monitor
    • DataDog
    • Prometheus
    • Grafana
    • ELK
      • Kibana
      • Logstash
  • BareMetal
    • NextCloud
  • Toggle search form

[K8s] Hướng dẫn sử dụng kubectl trên mấy local kết nối đến k8s master

Posted on July 25, 2021March 15, 2023 By nim 3 Comments on [K8s] Hướng dẫn sử dụng kubectl trên mấy local kết nối đến k8s master

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.

Contents

  • Writing a few helpful command kubectl
    • Hướng dẫn exec vào container:
    • Hướng dẫn copy 1 file từ conntainer ra local
    • Get secret registry
    • Delete evict pods
    • cordon and drain node with kubectl
  • Create secret from file
  • Deployment is used test(curl)
  • Delete the specific deployment on k8s
  • Delete the pod to be evicted

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>
Kubernetes, Kubernetes & Container

Post navigation

Previous Post: [SSL] Kích hoạt chứng chỉ Let’s Encrypt Wildcard SSL bằng docker
Next Post: [windows]Shutdown máy tính client bằng Domain controller

More Related Articles

[Kuberneste/Volume] How can you mount a volume on Kubernetes that its permission isn’t root (non-root) Kubernetes
[Kubernetes] Lesson3: k8s easy – Label and selector in Kubernetes Kubernetes & Container
[Metrics Server] Failed to make webhook authorizer request: the server could not find the requested resource Kubernetes
[Chartmuseum] Build yourself a Helm Chart Repository server Kubernetes & Container
Manage Kubernetes Secrets With External Secrets Operator AWS - Amazon Web Service
[Kubernetes] How to delete POD is Terminating and very stubborn Kubernetes

Comments (3) on “[K8s] Hướng dẫn sử dụng kubectl trên mấy local kết nối đến k8s master”

  1. Twicsy says:
    June 20, 2022 at 6:57 am

    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!

    Reply
  2. get instagram followers says:
    July 21, 2022 at 2:04 am

    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!

    Reply
    1. nim says:
      July 21, 2022 at 9:57 pm

      thank you for watching my post

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Tham Gia Group DevOps nhé!
Để Nim có nhiều động lực ra nhiều bài viết.
Để nhận được những thông báo mới nhất.

Recent Posts

  • [Prometheus/Grafana] Install Prometheus and Grafana on ubuntu. March 27, 2023
  • [Kong Gateway] WebSocket connection failed March 26, 2023
  • [Nextcloud] Can’t download files to have a size bigger than 2Gi on NextCloud – RaspBerry March 24, 2023
  • [Datadog] Using DataDog to monitor all services on kubernetes March 19, 2023
  • [Metrics Server] Failed to make webhook authorizer request: the server could not find the requested resource March 17, 2023

Archives

  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021

Categories

  • BareMetal
    • NextCloud
  • CI/CD
    • ArgoCD
    • ArgoWorkflows
    • Git
      • Bitbucket
    • Harbor
    • Jenkins
    • Spinnaker
    • TeamCity
  • Coding
    • Golang
    • Jquery & JavaScript
    • Laravel
    • Python
    • Selenium
    • Terraform
      • AWS – Amazon Web Service
      • GCP – Google Cloud
  • Kubernetes & Container
    • Apache Kafka
      • Kafka
      • Kafka Connect
      • Lenses
    • Docker
    • Helm Chart
    • Isito-EnvoyFilter
    • Kong Gateway
    • Kubernetes
      • Ingress
    • Longhorn – Storage
    • MetalLB
    • Vault
    • VictoriaMetrics
  • Log & Monitor
    • DataDog
    • ELK
      • Kibana
      • Logstash
    • Grafana
    • Prometheus
  • Uncategorized
  • Admin

Copyright © 2023 NimTechnology.