반응형

 

Node.js 에서 yaml 파일 읽고 쓰려면 간단히  js-yaml 라이브러리를 사용한다

 

1. install js-yaml

npm install js-yaml --save

 

2. Read & Write 

js-yaml 에서 제공하는 load와 dump 기능을 통해 사용한다.

const yaml = require('js-yaml');
const fs = require('fs');

const url = './config.yaml';

try {

    const file = yaml.load(fs.readFileSync(url), 'utf8');
    file.clusters[0].cluster.server = '192.168.0.1';
    fs.writeFileSync('./new-config.yaml', yaml.dump(file), 'utf8')

} catch (e) {
    console.log(e)
}

 

 

이렇게 간단하게 적용하면 되긴되나, 배열의 경우 옵션을 주지 않으면 아래와 같이 쓸모없는 indent가 추가된다.

 

기존 config.yaml

# config.yaml

apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: test
    server: https://127.0.0.1:6443

 

변경된 new-config.yaml

# new-config.yaml

apiVersion: v1
clusters:
  - cluster:
      certificate-authority-data: test
      server: 192.168.0.1
    name: dev-k8s

 

 

3. 이 경우 js-yaml 라이브러리에서 제공하는 noArrayIndent 를 사용하여 해결 가능하다.

const yaml = require('js-yaml');
const fs = require('fs');

const url = './config.yaml';

try {
    
    const file = yaml.load(fs.readFileSync(url), 'utf8');
    file.clusters[0].cluster.server = '192.168.0.1';
    fs.writeFileSync('./new-config.yaml', yaml.dump(file, {
        noArrayIndent: true
    }), 'utf8')

} catch (e) {
    console.log(e)
}

 

결과.

# new-config.yaml

apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: test
    server: 192.168.0.1
  name: dev-k8s

 

 

참고 : https://github.com/nodeca/js-yaml

반응형
반응형

 

kubectl api-resources 명령어를 통해 모든 리소스 조회 가능하다.

root@master:/# kubectl api-resources
NAME                              SHORTNAMES         APIVERSION                             NAMESPACED   KIND
bindings                                             v1                                     true         Binding
componentstatuses                 cs                 v1                                     false        ComponentStatus
configmaps                        cm                 v1                                     true         ConfigMap
endpoints                         ep                 v1                                     true         Endpoints
events                            ev                 v1                                     true         Event
limitranges                       limits             v1                                     true         LimitRange
namespaces                        ns                 v1                                     false        Namespace
nodes                             no                 v1                                     false        Node
persistentvolumeclaims            pvc                v1                                     true         PersistentVolumeClaim
persistentvolumes                 pv                 v1                                     false        PersistentVolume
pods                              po                 v1                                     true         Pod
podtemplates                                         v1                                     true         PodTemplate
replicationcontrollers            rc                 v1                                     true         ReplicationController
resourcequotas                    quota              v1                                     true         ResourceQuota
secrets                                              v1                                     true         Secret
serviceaccounts                   sa                 v1                                     true         ServiceAccount
services                          svc                v1                                     true         Service
mutatingwebhookconfigurations                        admissionregistration.k8s.io/v1        false        MutatingWebhookConfiguration
validatingwebhookconfigurations                      admissionregistration.k8s.io/v1        false        ValidatingWebhookConfiguration
customresourcedefinitions         crd,crds           apiextensions.k8s.io/v1                false        CustomResourceDefinition
apiservices                                          apiregistration.k8s.io/v1              false        APIService
controllerrevisions                                  apps/v1                                true         ControllerRevision
daemonsets                        ds                 apps/v1                                true         DaemonSet
deployments                       deploy             apps/v1                                true         Deployment
replicasets                       rs                 apps/v1                                true         ReplicaSet
statefulsets                      sts                apps/v1                                true         StatefulSet
applications                      app,apps           argoproj.io/v1alpha1                   true         Application
applicationsets                   appset,appsets     argoproj.io/v1alpha1                   true         ApplicationSet
appprojects                       appproj,appprojs   argoproj.io/v1alpha1                   true         AppProject
selfsubjectreviews                                   authentication.k8s.io/v1               false        SelfSubjectReview
tokenreviews                                         authentication.k8s.io/v1               false        TokenReview
localsubjectaccessreviews                            authorization.k8s.io/v1                true         LocalSubjectAccessReview
selfsubjectaccessreviews                             authorization.k8s.io/v1                false        SelfSubjectAccessReview
selfsubjectrulesreviews                              authorization.k8s.io/v1                false        SelfSubjectRulesReview
subjectaccessreviews                                 authorization.k8s.io/v1                false        SubjectAccessReview
horizontalpodautoscalers          hpa                autoscaling/v2                         true         HorizontalPodAutoscaler
cronjobs                          cj                 batch/v1                               true         CronJob
jobs                                                 batch/v1                               true         Job
certificatesigningrequests        csr                certificates.k8s.io/v1                 false        CertificateSigningRequest
leases                                               coordination.k8s.io/v1                 true         Lease
endpointslices                                       discovery.k8s.io/v1                    true         EndpointSlice
events                            ev                 events.k8s.io/v1                       true         Event
flowschemas                                          flowcontrol.apiserver.k8s.io/v1beta3   false        FlowSchema
prioritylevelconfigurations                          flowcontrol.apiserver.k8s.io/v1beta3   false        PriorityLevelConfiguration
ingressclasses                                       networking.k8s.io/v1                   false        IngressClass
ingresses                         ing                networking.k8s.io/v1                   true         Ingress
networkpolicies                   netpol             networking.k8s.io/v1                   true         NetworkPolicy
runtimeclasses                                       node.k8s.io/v1                         false        RuntimeClass
poddisruptionbudgets              pdb                policy/v1                              true         PodDisruptionBudget
clusterrolebindings                                  rbac.authorization.k8s.io/v1           false        ClusterRoleBinding
clusterroles                                         rbac.authorization.k8s.io/v1           false        ClusterRole
rolebindings                                         rbac.authorization.k8s.io/v1           true         RoleBinding
roles                                                rbac.authorization.k8s.io/v1           true         Role
priorityclasses                   pc                 scheduling.k8s.io/v1                   false        PriorityClass
csidrivers                                           storage.k8s.io/v1                      false        CSIDriver
csinodes                                             storage.k8s.io/v1                      false        CSINode
csistoragecapacities                                 storage.k8s.io/v1                      true         CSIStorageCapacity
storageclasses                    sc                 storage.k8s.io/v1                      false        StorageClass
volumeattachments                                    storage.k8s.io/v1                      false        VolumeAttachment

 

 

이 명령어를 잘 이용하면 각 서비스에 대한 yaml파일들을 백업할 수 있다.

#!/bin/sh

DIR=/k8s-bak/resouruces # 경로 입력

mkdir -p 

for NS in $(kubectl get ns --no-headers | awk '{ print $1 }') # 모든 Namespace 조회
do
    mkdir -p ${DIR}/${NS} # 각 Namespace 별 폴더 생성
    for RESOURCE in $(kubectl api-resources --no-headers | awk '{ print $1 }') # 리소스 조회
    do
        kubectl get ${RESOURCE} -n ${NS} -o yaml > ${DIR}/${NS}/${RESOURCE}.yaml # YAML 백업
    done
done

 

실행결과

root@master:~# ./bak.yaml

root@master:/k8s-bak/resources# ls
argocd  default  ingress-nginx  kube-node-lease  kube-public  kube-system

root@master:/k8s-bak/resources# cd argocd/

root@master:/k8s-bak/resources/argocd# ls
apiservices.yaml                 mutatingwebhookconfigurations.yaml
applicationsets.yaml             namespaces.yaml
applications.yaml                networkpolicies.yaml
appprojects.yaml                 nodes.yaml
bindings.yaml                    persistentvolumeclaims.yaml
certificatesigningrequests.yaml  persistentvolumes.yaml
clusterrolebindings.yaml         poddisruptionbudgets.yaml
clusterroles.yaml                pods.yaml
componentstatuses.yaml           podtemplates.yaml
configmaps.yaml                  priorityclasses.yaml
controllerrevisions.yaml         prioritylevelconfigurations.yaml
cronjobs.yaml                    replicasets.yaml
csidrivers.yaml                  replicationcontrollers.yaml
csinodes.yaml                    resourcequotas.yaml
csistoragecapacities.yaml        rolebindings.yaml
customresourcedefinitions.yaml   roles.yaml
daemonsets.yaml                  runtimeclasses.yaml
deployments.yaml                 secrets.yaml
endpointslices.yaml              selfsubjectaccessreviews.yaml
endpoints.yaml                   selfsubjectreviews.yaml
events.yaml                      selfsubjectrulesreviews.yaml
flowschemas.yaml                 serviceaccounts.yaml
horizontalpodautoscalers.yaml    services.yaml
ingressclasses.yaml              statefulsets.yaml
ingresses.yaml                   storageclasses.yaml
jobs.yaml                        subjectaccessreviews.yaml
leases.yaml                      tokenreviews.yaml
limitranges.yaml                 validatingwebhookconfigurations.yaml
localsubjectaccessreviews.yaml   volumeattachments.yaml
반응형
반응형

kubectl 도구를 이용하여 Windows에서 기타 서버에 설치되어있는 k8s cluster를 사용할 수 있으며,

k8s 클러스터가 여러개일 경우에도 선택하여 사용가능하다.

 

1. k8s 설치

Window에 Terminal 또는 Powershell을 열어 아래의 명령어를 통해 kubectl을 다운받는다.

curl.exe -LO "https://dl.k8s.io/release/v1.28.4/bin/windows/amd64/kubectl.exe"

 

다운 후 Path에 등록하여도 되고 직접 kubectl 설치되어있는 폴더 호출 하여 사용해도 무관.

# C드라이브 test폴더에서 kubectl 파일 다운받았을 경우
C:\test> ./kubectl

 

 

2. k8s config 파일 복사

서버에 있는 k8s config파일의 내용을 복사한다.

cat ~/.kube/config

apiVersion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zJMc1cKTnRxVm5kM3hibVpFTDREamM4ZWNmYVJZMHJTMm9yQ3RoZzZQZFZhMTdQaWlWTk1zS0hGSnJpMVRPdEY5VzdKYQpNQkRLN2ttL2syZThnRmJPYzhlZHc5VGVmS09QTFBLenN6NXVzbWRCNnVyNnZxRFlUYWhtVi9UV2NrQW04aFd6ClU4bkxDcEE1VVllV3hkbTBJSGU2L0NOUmNEeXQzUEtOQTlMZm5zeHcxZjh5c24zSElSSTc2REhyVE9OK3lQUjQKRFpacjI5YjRsWkVtCi0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K
    server: https://192.168.1.1:6443
  name: dev-k8s
contexts:
- context:
    cluster: dev-k8s
    user: pangyeon
  name: pangyeon-dev
current-context:  pangyeon-dev
kind: Config
preferences: {}
users:
- name: pangyeon
  user:
    client-certificate-data: LS0tLS1CRUdJTiBSUZJQDQWdtZ0F3SUJBZ0lJSGpubTVYZWxsbk13RFFZSktvWklodmNOQVFFTEJRQXdGVEVUTUJFR0ExVUUKQXhNS2EzVmlaWEp1WlhSbGN6QWVGdzB5TXpBNE1qRXhNelV4TlROYUZ3MHlOREE0TWpBeE16VTJOVFphTURReApGekFWQmdOVkJBb1REbk41YzNSbGJUcHRZWE4wWlhKek1Sa3dGd1lEVlFRREV4QnJkV0psY201bGRHVnpMV0ZrCmJXbHVNSUlCSWpBTkJna3Foa2lHOXcwQkFRRUZBQU9DQVE4QU1JSUJDZ0tDQVFFQTJ0QVJiWnBiUmNsdFZXRjAKaldFVCt4ZlJ6NC9naG0rYlhCM3Y1clphVzNNSkxxT0JaSGNaZUJPTEFCTmtvbk5nK3BQTVRndmNQSzQ1TGlBRgo3a0orbXg5UWVUbm0va2U5Rm1FQSswNDRIMlFmczFQOTk1ZWRrZHdZZ1RBNzhUWHc5MnNkWUZ4ZjJKNHpEV3YvCjJiSjkxR0ozSUhMYTNzeGwxRlEvS1Q3ZmFYa0U1Sk5Id283ZStYYVdBTmNET0hUT1Z5SjBYTzdEamJZeHp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4aU1PaXkzR0pJVlJ1SzY1N005QWsyZFF3blJDeWZTbUZXNzdHMTdRc1RWQy9uVXVueHRMNGNiVEhaRndVMgo2dXVIUUg2QUNMS2p1ek03djJ3MERsZUNlbG1TKzFaelZvS2I2Mmc2S3pUZXZ2bWhrczI0Vkxtc1BMT0lta1pGCndHSmJoT1lFcDhXcktZalZQNzJXSmg4bXhLVFBUSVhFNTZKSzZIL1pBb0dCQU0yQXUxaHhqdVU3M1IyMGxRK00KTkRyL3hrN3l4QktVUTBOZkFWWU5tUThLU25kanJYSnQyVnFyNi80cStHZ2VieDBnbmozOEJKbG9Rc1pSdUVOWgpBR2FJVy9kN2hsTkFDNFN5K3NqSGlRWmZKYVhtL2RaSEdoNkhRaFo1cnhOenZjNDNBc1BQaGp0TzBYWkt1UDVMClliY01FcHdCcHJCbmlIV0NTUEZ1MHI2bEFvR0FSUGdYUlJIZ3J2dUlDV1NYYmgwSTZMUFkwRGRtaFNtbExiK1cKMGhqMUF1Q1ZjUkc4UE04Vkc4cXdOTGdkS0d0Q0FXckw2bExwRC9lK0ZjaE9ja3dQODg4WGdvR3VMVW9oY0k4cgpqZXY3WEx6dDMzZWM3NkdIZDgrcE5sR2lBME9ObkNCdXhhOTh3eElNdDh4enhWQnBnOWhrMmZIRDkyZE1XMXFlCmJaaTB3b2tDZ1lFQTdoWUNYSXlXQkpkU3lrMnNPakVndHdLY3AwY2VxUC9sd2QwbGFya2VDU1laSEtweGY5TSsKMm93dGd6UzFTZ1pibHlvRytMQzVFRkF6cXJIK002aHdXZCtMcG8yeWhBZ1hVNm9SMDlNdG56ZUo0UGhBTzI5WQo1ejNiZHp5Q1RNZlN4RUYweWNOL21yZnI1N2VGVk51d1ZnUkVySWxkVGw5NkRaVENXS2ZDb0h3PQotLS0tLUVORCBSU0EgUFJJVkFURSBS0tLQo=

 

 

3. 복사한 파일 이동 및 조회

아래 두가지 방법으로 사용가능

 

3.1 Windows 계정 폴더로 이동

C:\Users\본인계정\  으로 이동하여 .kube 폴더 생성 후 아래에 config파일 이동

 

C:\Users\본인계정\.kube\config 에 파일이 있을 경우 바로 사용가능하다.

# C드라이브 test에 kubectl 파일이 있는 경우
PS C:\test> ./kubectl get pods -A
NAMESPACE       NAME                                                READY   STATUS        RESTARTS       AGE
ingress-nginx   ingress-nginx-controller-6544f7745b-z4lsr           1/1     Running       1 (52m ago)    24h
kube-system     coredns-5dd5756b68-2tl8x                            1/1     Terminating   0              1d
kube-system     coredns-5dd5756b68-6b55b                            1/1     Terminating   0              1d
kube-system     coredns-5dd5756b68-7fxrc                            1/1     Running       8 (52m ago)    1d
kube-system     coredns-5dd5756b68-h982d                            1/1     Running       9 (52m ago)    1d
kube-system     etcd-ubuntu                                         1/1     Running       0              1d
kube-system     kube-apiserver-ubuntu                               1/1     Running       0              1d
kube-system     kube-controller-manager-ubuntu                      1/1     Running       0              1d
kube-system     kube-proxy-2sngh                                    1/1     Running       9 (52m ago)    1d
kube-system     kube-proxy-mmsbf                                    1/1     Running       10 (52m ago)   1d
kube-system     kube-proxy-zh22k                                    1/1     Running       0              1d
kube-system     kube-scheduler-ubuntu                               1/1     Running       0              1d
kube-system     weave-net-94f8g                                     2/2     Running       24 (52m ago)   1d
kube-system     weave-net-gszsj                                     2/2     Running       30 (51m ago)   1d
kube-system     weave-net-hxknh                                     2/2     Running       1 (99d ago)    1d

 

 

3.2 사용하기 편한곳에 config 파일두고 kubectl --kubeconfig 옵션을 통해 사용

# C드라이브 내 test폴더에 config파일이 있을 경우
./kubectl get pods -A --kubeconfig=C:\test\config
NAMESPACE       NAME                                                READY   STATUS        RESTARTS       AGE
ingress-nginx   ingress-nginx-controller-6544f7745b-z4lsr           1/1     Running       1 (52m ago)    24h
kube-system     coredns-5dd5756b68-2tl8x                            1/1     Terminating   0              1d
kube-system     coredns-5dd5756b68-6b55b                            1/1     Terminating   0              1d
kube-system     coredns-5dd5756b68-7fxrc                            1/1     Running       8 (52m ago)    1d
kube-system     coredns-5dd5756b68-h982d                            1/1     Running       9 (52m ago)    1d
kube-system     etcd-ubuntu                                         1/1     Running       0              1d
kube-system     kube-apiserver-ubuntu                               1/1     Running       0              1d
kube-system     kube-controller-manager-ubuntu                      1/1     Running       0              1d
kube-system     kube-proxy-2sngh                                    1/1     Running       9 (52m ago)    1d
kube-system     kube-proxy-mmsbf                                    1/1     Running       10 (52m ago)   1d
kube-system     kube-proxy-zh22k                                    1/1     Running       0              1d
kube-system     kube-scheduler-ubuntu                               1/1     Running       0              1d
kube-system     weave-net-94f8g                                     2/2     Running       24 (52m ago)   1d
kube-system     weave-net-gszsj                                     2/2     Running       30 (51m ago)   1d
kube-system     weave-net-hxknh                                     2/2     Running       1 (99d ago)    1d

 

 

4. k8s 클러스터가 여러개일경우

config 파일에 등록한다.

apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURCVENDQWUyZ0F3SUJBZ0lJTC9XdXZlY1ZxL013RFFZSktvWklodmNOQVFFTEJRQXdGVEVUTUJFR0ExVUUKQXhNS2EzVmlaWEp1WlhSbGN6QWVGdzB5TXpBNE1qRXhNelV4TlROYUZ3MHpNekE0TVRneE16VTJOVE5hTUJVeApFekFSQmdOVkJBTVRDbXQxWW1WeWJtVjBaWE13Z2dFaU1BMEdDU3FHU0liM0RRRUJBUVVBQTRJQkR3QXdnZ0VLCkFvSUJBUURmZTZSREhXZE90Q25qczZnNHFESVprZHFzR2ZRUEE5MXlWYS9LN3AwcTZIRllvRzRQcGZHMkdUeFIKWi9HeXFqU3ZIS01KYWo1WUIvdHJ1TEtrMnoreTFGZXp0eHJFc1JkVi96UXlNOENrcGZVd1FhV2dNMGhSUTF3NgpKcTZGOHhsMlBSaDFlRjJ1eG9YT0pPOFFGam1EV2lUWVQrNEhTL0dRRE5hTlYvNlAxOXllM2VNQWhyZndQeU4xCkJKWXNwRnBTRFJLMTNpNG1IYTk3ZS9WMU9iQkFaQlJNZHhYc3FsaHQvaDR3UWFaRGF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TdQaWlWTk1zS0hGSnJpMVRPdEY5VzdKYQpNQkRLN2ttL2syZThnRmJPYzhlZHc5VGVmS09QTFBLenN6NXVzbWRCNnVyNnZxRFlUYWhtVi9UV2NrQW04aFd6ClU4bkxDcEE1VVllV3hkbTBJSGU2L0NOUmNEeXQzUEtOQTlMZm5zeHcxZjh5c24zSElSSTc2REhyVE9OK3lQUjQKRFpacjI5YjRsWkVtCi0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K
    server: https://192.168.2.1:6443
  name: stg-k8s
contexts:
- context:
    cluster: dev-k8s
    user: pangyeon-dev
  name: pangyeon-dev
- context:
    cluster: stg-k8s
    user: pangyeon-stg
  name: pangyeon-stg
current-context: pangyeon-dev
kind: Config
preferences: {}
users:
- name: pangyeon-dev
  user:
    client-certificate-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURJVENDQWdtZ0F3SUJBZ0lJSGpubTVYZWxsbk13RFFZSktvWklodmNOQVFFTEJRQXdGVEVUTUJFR0ExVUUKQXhNS2EzVmlaWEp1WlhSbGN6QWVGdzB5TXpBNE1qRXhNelV4TlROYUZ3MHlOREE0TWpBeE16VTJOVFphTURReApGekFWQmdOVkJBb1REbk41YzNSbGJUcHRZWE4wWlhKek1Sa3dGd1lEVlFRREV4QnJkV0psY201bGRHVnpMV0ZrCmJXbHVNSUlCSWpBTkJna3Foa2lHOXcwQkFRRUZBQU9DQVE4QU1JSUJDZ0tDQVFFQTJ0QVJiWnBiUmNsdFZXRjAKaldFVCt4ZlJ6NC9naG0rYlhCM3Y1clphVzNNSkxxT0JaSGNaZUJPTEFCTmtvbk5nK3BQTVRndmNQSzQ1TGlBRgo3a0orbXg5UWVUbm0va2U5Rm1FQSswNDRIMlFmczFQOTk1ZWRrZHdZZ1RBNzhUWHc5MnNkWUZ4ZjJKNHpEV3YvCjJiSjkxR0ozSUhMYTNzeGwxRlEvS1Q3ZmFYa0U1Sk5Id283ZStYYVdBTmNET0hUT1Z5SjB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enZjNDNBc1BQaGp0TzBYWkt1UDVMClliY01FcHdCcHJCbmlIV0NTUEZ1MHI2bEFvR0FSUGdYUlJIZ3J2dUlDV1NYYmgwSTZMUFkwRGRtaFNtbExiK1cKMGhqMUF1Q1ZjUkc4UE04Vkc4cXdOTGdkS0d0Q0FXckw2bExwRC9lK0ZjaE9ja3dQODg4WGdvR3VMVW9oY0k4cgpqZXY3WEx6dDMzZWM3NkdIZDgrcE5sR2lBME9ObkNCdXhhOTh3eElNdDh4enhWQnBnOWhrMmZIRDkyZE1XMXFlCmJaaTB3b2tDZ1lFQTdoWUNYSXlXQkpkU3lrMnNPakVndHdLY3AwY2VxUC9sd2QwbGFya2VDU1laSEtweGY5TSsKMm93dGd6UzFTZ1pibHlvRytMQzVFRkF6cXJIK002aHdXZCtMcG8yeWhBZ1hVNm9SMDlNdG56ZUo0UGhBTzI5WQo1ejNiZHp5Q1RNZlN4RUYweWNOL21yZnI1N2VGVk51d1ZnUkVySWxkVGw5NkRaVENXS2ZDb0h3PQotLS0tLUVORCBSU0EgUFJJVkFURSBLRVktLS0tLQo=

 

 

5. use-context 옵션을 통해 클러스터를 선택한다.

PS C:\test> ./kubectl config use-context pangyeon-dev
Switched to context "pangyeon-dev".

 

 

6. 선택 후 조회

./kubectl get pods -A
NAMESPACE       NAME                                                READY   STATUS        RESTARTS       AGE
ingress-nginx   ingress-nginx-controller-6544f7745b-z4lsr           1/1     Running       1 (52m ago)    24h
kube-system     coredns-5dd5756b68-2tl8x                            1/1     Terminating   0              1d
kube-system     coredns-5dd5756b68-6b55b                            1/1     Terminating   0              1d
kube-system     coredns-5dd5756b68-7fxrc                            1/1     Running       8 (52m ago)    1d
kube-system     coredns-5dd5756b68-h982d                            1/1     Running       9 (52m ago)    1d
kube-system     etcd-ubuntu                                         1/1     Running       0              1d
kube-system     kube-apiserver-ubuntu                               1/1     Running       0              1d
kube-system     kube-controller-manager-ubuntu                      1/1     Running       0              1d
kube-system     kube-proxy-2sngh                                    1/1     Running       9 (52m ago)    1d
kube-system     kube-proxy-mmsbf                                    1/1     Running       10 (52m ago)   1d
kube-system     kube-proxy-zh22k                                    1/1     Running       0              1d
kube-system     kube-scheduler-ubuntu                               1/1     Running       0              1d
kube-system     weave-net-94f8g                                     2/2     Running       24 (52m ago)   1d
kube-system     weave-net-gszsj                                     2/2     Running       30 (51m ago)   1d
kube-system     weave-net-hxknh                                     2/2     Running       1 (99d ago)    1d

 

 

참고

https://kubernetes.io/ko/docs/tasks/tools/install-kubectl-windows/

https://kubernetes.io/docs/tasks/access-application-cluster/configure-access-multiple-clusters/

반응형
반응형

 

1. etcdctl leader 및 list 조회 명령어 입력시 Error: context deadline exceeded 발생할 경우 cacert, cert, key를 입력해준다.

# 아래 두개 중 하나 사용
etcdctl member list --cacert="/etc/kubernetes/pki/etcd/ca.crt" --cert="/etc/kubernetes/pki/etcd/peer.crt" --key="/etc/kubernetes/pki/etcd/peer.key"
or
etcdctl member list --cacert="/etc/kubernetes/pki/etcd/ca.crt" --cert="/etc/kubernetes/pki/etcd/server.crt" --key="/etc/kubernetes/pki/etcd/server.key"

 

 

2. etcdctl 사용시 open /etc/kubernetes/pki/etcd/ca.crt: permission denied 발생할 경우

kube-system의 etcd 버전과 맞춰준다.

cat /etc/kubernetes/manifests/etcd.yaml | grep image
# image: image: registry.k8s.io/etcd:3.5.9-0 
# 위 image 버전확인 후 etcdctl 다운
# https://github.com/etcd-io/etcd/releases
curl https://storage.googleapis.com/etcd/v3.5.9/etcd-v3.5.9-linux-amd64.tar.gz -o ./etcd-v3.5.9-linux-amd64.tar.gz
반응형
반응형

1. pods 전체삭제

 # Pods 전체 삭제
 kubectl delete pods --all --all-namespaces
 kubectl delete pods --all -A
 
 # Namespace 별 삭제
 kubectl delete pods --all -n test

 

 

2. pods 특정 이름으로 삭제

<namespace> 자리에 namespace 입력 - test

/application/ 자리에 삭제할 이름 입력 - /nginx/

kubectl get pods -n <namespace> --no-headers=true | awk '/application/{print $1}'| xargs  kubectl delete -n <namespace> pod

#namesapce가 test이고 test namespace안에 nginx라는 이름이 들어가는 pods 전체 삭제
kubectl get pods -n test --no-headers=true | awk '/nginx/{print $1}'| xargs  kubectl delete -n test pod

 

 

참고 : 

https://www.baeldung.com/linux/kubernetes-delete-all-pods

https://stackoverflow.com/questions/59473707/kubernetes-pod-delete-with-pattern-match-or-wildcard

반응형
반응형

Javscript로 동적으로 CSS추가가 필요할 경우 document.createElement("style") 을 통해 가능하다.

 

아래와같이 적용할 경우 버튼태그가 testBtn인경우(<button id="testBtn">) 빨간색 및 테두리가 생기는 CSS Style이

head태그쪽에 생성된다.

 

let testStyle = document.createElement("style")

let testBtn = `#testcss {
	border: solid;
    color : red;
}`

testStyle.appendChild(document.createTextNode(testBtn))
document.head.appendChild(testStyle)

 

반응형
반응형

 

Nginx의 auth_request 기능을 사용하고 싶었지만, apache에는 이와 비슷한 기능이 없는 것 같아

AuthType이라는것을 사용하였다.

 

1. 사용전 htpasswd 확인

htpasswd는 기본적으로 Apach생성 경로의 bin폴더에 있다.

# Apache 가 /usr/local 폴더에 있을경우
/usr/local/apache/bin/htpasswd

 

bin폴더에 없을경우 httpd를 설치한다. - https://httpd.apache.org/download.cgi#apache24

 

2. htpasswd를 통해 계정과 비밀번호를 생성

-c 는 create 옵션이고 /home/test 폴더 내에 .htpasswd 파일을 생성하고

해당 파일에 user1이라는 계정과 패스워드를 관리한다

# Input
./htpasswd -c /home/test/.htpasswd user1

# Output
cat /home/test.htpasswd
user1:$apr1$.0CAabqX$rsdf8sdSDFgs/p90SDGcvb1Gs/

 

 

3. AuthType 설정

사용 중인 conf파일에 설정 후 아파치 재시작한다.

<Location "/private">

AuthType Basic
AuthName "Authentication required"
AuthUserFile /home/test/.htpasswd
Require valid-uesr

</Location>

 

 

기타.

이렇게 설정할 경우 기본적으로 웹사이트에 로그인하는 로직이 있다면 해당 세션이 끊기게되는데

아래 설정을 추가할 경우 해결할 수 있긴하다.

RequestHeader unset Authorization
<Location "/private">

AuthType Basic
AuthName "Authentication required"
AuthUserFile /home/test/.htpasswd
Require valid-uesr

</Location>

 

 

https://httpd.apache.org/docs/2.4/en/howto/auth.html

반응형
반응형

 

Version

- Ubuntu 20.04

- Docker 24.0.5

- kubernetes 1.28.0

 

※ Master 1대 Woker 2대

 

1. 전부 root 계정으로 시작한다.

sudo -i

 

2. 모든 서버 Hostname 변경

변경 안 할 시 node 등록할 때 에러 발생

# Master server 1
hostnamectl set-hostname Master

# Worker server 1
hostnamectl set-hostname Node1

# Worker server 2
hostnamectl set-hostname Node2

 

3. Docker 설치 (Master, Woker 전부 진행)

apt-get update
apt-get install \
    ca-certificates \
    curl \
    gnupg \
    lsb-release
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
 echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
apt-get update
apt-get install docker-ce docker-ce-cli containerd.io

모든 서버에 설치 후 Docker Version 확인

 docker version

 

4. Kubernetes (k8s) 설치 (Master, Worker 전부 실행)

swapoff -a && sudo sed -i '/swap/s/^/#/' /etc/fstab

 

iptable 설정

cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
br_netfilter
EOF
cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system

 

kubectl, kubeadm, kubelet 설치

apt-get update
apt-get install -y apt-transport-https ca-certificates curl
curl -fsSL https://packages.cloud.google.com/apt/doc/apt-key.gpg| gpg -o /usr/share/keyrings/kubernetes-archive-keyring.gpg --dearmor
echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
apt-get update
apt-get install -y kubelet kubeadm kubectl
apt-mark hold kubelet kubeadm kubectl
systemctl daemon-reload
systemctl restart kubelet

 

5. kubeadm init (Master에만 진행)

kubeadm init 실행시 아래 에러 발생

unix:///var/run/containerd/containerd.sock\": rpc error: code = Unimplemented desc = unknown service runtime.v1.RuntimeService" 

참고 : https://github.com/containerd/containerd/issues/4581

해당 작업만 모든 서버(Master, Worker에서 진행)

# 해당작업만 모든 서버(Master, Worker)에서 진행
rm etc/containerd/config.toml
systemctl restart containerd

작업 후 아래 명령어 진행

kubeadm init

정상적으로 성공할 경우 아래 값 반환 해당값 메모장에 임시 저장

kubeadm join 192.x.x.x:6443 --token c5l89v.9ao1r5texepx06d8 \
	--discovery-token-ca-cert-hash sha256:50cb3eaxe334612e81c2342790130801afd70ddb9967a06bb0b202141748354f

모든 User를 위해 명령어 등록

mkdir -p $HOME/.kube
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
chown $(id -u):$(id -g) $HOME/.kube/config

 

6. Pod Network 설치 (Master에서만 진행)

https://cloud.weave.works 서버가 이상하므로 github에서 다운받는다. 현재 작성일 기준 2.8.1이 최신

kubectl apply -f https://github.com/weaveworks/weave/releases/download/v2.8.1/weave-daemonset-k8s-1.11.yaml

 

7. Node 등록 (Woker에서만 진행)

5번에서 저장한 kubeadm join 입력

kubeadm join 192.x.x.x:6443 --token c5l89v.9ao1r5texepx06d8 \
	--discovery-token-ca-cert-hash sha256:50cb3eaxe334612e81c2342790130801afd70ddb9967a06bb0b202141748354f

 

8. Master에서 확인

Master에서 아래 명령어 실행

kubectl get nodes -o wide

해당 가이드대로 진행하였으면 아래 사진에서 ubuntu -> master로 나와야함

 

 

반응형
반응형

 

Java에서 Inner Class 사용시 발생하는 No enclosing instance of type is accessible 해결 방법이다.

 

아래와 같이 java 파일들이 구성되어있고 Hello.java 파일안에 World 라는 inner class가 있을 경우

public class Hello {
	private int id;

	public Hello() {
		super();
	}

	public Hello(int id) {
		super();
		this.id = id;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public class World {		
		private String name;

		public World() {
			super();
		}

		public World(String name) {
			super();
			this.name = name;
		}

		public String getName() {
			return name;
		}

		public void setName(String name) {
			this.name = name;
		}			
		
	}
}

 

Hello안에있는 World Class를 사용하기 위해서 Hello Class를 먼저 생성 후 World Class를 호출한다.

import test3.Hello.World;

public class Main {

	public static void main(String[] args) {

		Hello hello = new Hello();
		World world = hello.new World();
				
	}

}
반응형
반응형

다운로드 - https://github.com/wonkwangyeon/Add-Windows-Run/releases

 

Releases · wonkwangyeon/Add-Windows-Run

Windows의 실행에서 파일을 실행하고 관리하는 프로그램. Contribute to wonkwangyeon/Add-Windows-Run development by creating an account on GitHub.

github.com

git source - https://github.com/wonkwangyeon/Add-Windows-Run

 

GitHub - wonkwangyeon/Add-Windows-Run: Windows의 실행에서 파일을 실행하고 관리하는 프로그램

Windows의 실행에서 파일을 실행하고 관리하는 프로그램. Contribute to wonkwangyeon/Add-Windows-Run development by creating an account on GitHub.

github.com

 

Winodws 의 실행에서 파일을 실행하기위해 레지스트리를 편집해서 작성해야하지만

해당 프로그램을 이용하면 레지스트리 편집기를 열지않아도 추가가능하며,

어느것을 추가했는지 관리가능하며, 삭제까지 가능한 프로그램.

 

1. 소개

Windows의 실행에서 파일을 실행할 수 있도록 등록 및 관리하는 프로그램

사용언어 - Python

사용 DB - SqlLite

2. 기능

  • 실행할 파일 레지스트리에 추가
  • 추가한 파일 삭제

3. 사용방법

  1. 추가

  • Run Name :
    • 실행에서 파일을 실행할 명령어 등록 ex) vscode.exe
  • Run File Path :
    • 실행 파일이 위치한 폴더 경로 ex) C:\Users\VSCode
  • Run File.exe :
    • 실제 exe 파일 ex) Code.exe
  1. 삭제
  • 삭제할 항목 클릭 후 Delete 버튼 클릭
  1. 확인

  • 실행창에서 등록한 명령어를 통해 실행확인

  • 레지스트리편집기에서 추가 및 삭제 확인
  1. 실행 및 실패 로그는 4번의 DB 및 Log경로에서 확인가능

4. DB 및 Log 경로

C:\addWindowsRun

  • DB.log
    • DB 실행 로그
  • AddWindowsRun.log
    • 프로그램 시작 로그
  • Run.log
    • 실행 로그
  • addWindowsRun.db
    • 추가한 파일 및 경로를 저장하는 DB
반응형

+ Recent posts