■ 목적
MASTER1대 + NODE 3대의 쿠버네티스 클러스터 구축
 

 


■ OS설치
대상: master 1대 + node 3대
Linux 계열 OS 설치
 
 

■ OS 기본 환경 구성
대상: master 1대 + node 3대

 

[yum 최신 업데이트 및 추가 유틸리티 설치]
yum -y update
yum install -y yum-utils  device-mapper-persistent-data   lvm2 net-tools

 

[SWAP 설정 Off, 방화벽 Off, SELINUX Disabled 적용]
swapoff -a && sed -i '/swap/s/^/#/' /etc/fstab
systemctl stop firewalld && systemctl disable firewalld
setenforce 0
sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config
 

■ hosts파일 수정
대상: master 1대 + node 3대
/etc/hosts에 아래와 같이 설정 추가 (IP는 본인 서버 설정에 맞게 적용)
 
192.168.114.128 master1
192.168.114.131 node1
192.168.114.129 node12
192.168.114.130 node13
 

■ Docker 설치
대상: master 1대 + node 3대
 
yum-config-manager    --add-repo     https://download.docker.com/linux/centos/docker-ce.repo
yum install docker-ce docker-ce-cli containerd.io -y
 

■ Docker 기동
대상: master 1대 + node 3대
systemctl start docker && systemctl enable docker
 

Kubernetes 기본 환경 구성
대상: master 1대 + node 3대
 
[SWAP 설정 Off, 방화벽 Off, SELINUX Disabled 적용]
swapoff -a && sed -i '/swap/s/^/#/' /etc/fstab
systemctl stop firewalld && systemctl disable firewalld
 
 
[네트워크 관련 OS Kenel Tuning]
cat <<EOF >  /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system
 
 
[K8S관련 yum Repository 추가]
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
enabled=1
gpgcheck=1
repo_gpgcheck=1
EOF
 
[K8S 패키지 설치]
yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes
systemctl enable --now kubelet && systemctl start kubelet
 

Master 서버 생성
대상: master 1대
kubeadm init --pod-network-cidr 10.244.0.0/16
--pod-network-cidr=10.244.0.0/16 은 Flannel 에서 사용하는 설정이며 변경 가능.
 
아래 붉은색으로 표시된 부분은 반드시 별도 저장해 둘것
 
# kubeadm init --pod-network-cidr 10.244.0.0/16
[init] using Kubernetes version: v1.11.2
[preflight] running pre-flight checks
I0903 19:18:37.032588   86064 kernel_validator.go:81] Validating kernel version
I0903 19:18:37.032757   86064 kernel_validator.go:96] Validating kernel config
[preflight/images] Pulling images required for setting up a Kubernetes cluster
[preflight/images] This might take a minute or two, depending on the speed of yo                                           ur internet connection
[preflight/images] You can also perform this action in beforehand using 'kubeadm                                            config images pull'
[kubelet] Writing kubelet environment file with flags to file "/var/lib/kubelet/                                           kubeadm-flags.env"
[kubelet] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
[preflight] Activating the kubelet service
[certificates] Generated ca certificate and key.
[certificates] Generated apiserver certificate and key.
[certificates] apiserver serving cert is signed for DNS names [test-k8s-master-n                                           cl kubernetes kubernetes.default kubernetes.default.svc kubernetes.default.svc.c                                           luster.local] and IPs [10.96.0.1 10.106.234.130]
[certificates] Generated apiserver-kubelet-client certificate and key.
[certificates] Generated sa key and public key.
[certificates] Generated front-proxy-ca certificate and key.
[certificates] Generated front-proxy-client certificate and key.
[certificates] Generated etcd/ca certificate and key.
[certificates] Generated etcd/server certificate and key.
[certificates] etcd/server serving cert is signed for DNS names [test-k8s-master                                           -ncl localhost] and IPs [127.0.0.1 ::1]
[certificates] Generated etcd/peer certificate and key.
[certificates] etcd/peer serving cert is signed for DNS names [test-k8s-master-n                                           cl localhost] and IPs [10.106.234.130 127.0.0.1 ::1]
[certificates] Generated etcd/healthcheck-client certificate and key.
[certificates] Generated apiserver-etcd-client certificate and key.
[certificates] valid certificates and keys now exist in "/etc/kubernetes/pki"
[kubeconfig] Wrote KubeConfig file to disk: "/etc/kubernetes/admin.conf"
[kubeconfig] Wrote KubeConfig file to disk: "/etc/kubernetes/kubelet.conf"
[kubeconfig] Wrote KubeConfig file to disk: "/etc/kubernetes/controller-manager.                                           conf"
[kubeconfig] Wrote KubeConfig file to disk: "/etc/kubernetes/scheduler.conf"
[controlplane] wrote Static Pod manifest for component kube-apiserver to "/etc/k                                           ubernetes/manifests/kube-apiserver.yaml"
[controlplane] wrote Static Pod manifest for component kube-controller-manager t                                           o "/etc/kubernetes/manifests/kube-controller-manager.yaml"
[controlplane] wrote Static Pod manifest for component kube-scheduler to "/etc/k                                           ubernetes/manifests/kube-scheduler.yaml"
[etcd] Wrote Static Pod manifest for a local etcd instance to "/etc/kubernetes/m                                           anifests/etcd.yaml"
[init] waiting for the kubelet to boot up the control plane as Static Pods from                                            directory "/etc/kubernetes/manifests"
[init] this might take a minute or longer if the control plane images have to be                                            pulled
[apiclient] All control plane components are healthy after 40.501916 seconds
[uploadconfig] storing the configuration used in ConfigMap "kubeadm-config" in t                                           he "kube-system" Namespace
[kubelet] Creating a ConfigMap "kubelet-config-1.11" in namespace kube-system wi                                           th the configuration for the kubelets in the cluster
[markmaster] Marking the node test-k8s-master-ncl as master by adding the label                                            "node-role.kubernetes.io/master=''"
[markmaster] Marking the node test-k8s-master-ncl as master by adding the taints                                            [node-role.kubernetes.io/master:NoSchedule]
[patchnode] Uploading the CRI Socket information "/var/run/dockershim.sock" to t                                           he Node API object "test-k8s-master-ncl" as an annotation
[bootstraptoken] using token: pvpoff.3gi89fsxl6q6vq21
[bootstraptoken] configured RBAC rules to allow Node Bootstrap tokens to post CS                                           Rs in order for nodes to get long term certificate credentials
[bootstraptoken] configured RBAC rules to allow the csrapprover controller autom                                           atically approve CSRs from a Node Bootstrap Token
[bootstraptoken] configured RBAC rules to allow certificate rotation for all nod                                           e client certificates in the cluster
[bootstraptoken] creating the "cluster-info" ConfigMap in the "kube-public" name                                           space
[addons] Applied essential addon: CoreDNS
[addons] Applied essential addon: kube-proxy
 
Your Kubernetes master has initialized successfully!
 
To start using your cluster, you need to run the following as a regular user:
 
  mkdir -p $HOME/.kube
  sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  sudo chown $(id -u):$(id -g) $HOME/.kube/config
 
You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
 
You can now join any number of machines by running the following on each node
as root:
 
  kubeadm join 192.168.114.128:6443 --token pvpoff.3gi19fsxl8q6vq47 --discovery-t                                           oken-ca-cert-hash sha256:e57e547d3697386005324524878f42b670db3f83227ff247464f470                                           f2fddf2d6
 
 
 

Flannel Network 설치
대상: master 1대
 
 
clusterrole.rbac.authorization.k8s.io/flannel created
clusterrolebinding.rbac.authorization.k8s.io/flannel created
serviceaccount/flannel created
configmap/kube-flannel-cfg created
daemonset.extensions/kube-flannel-ds created
 

 


Kubectl 명령어 환경 설정 구성
대상: master 1대 및 필요한 서버
 
kubectl 클라이언트로 사용할 계정 환경 구성.
아까 master서버에서 별도 기록한 설정을 복사한다.
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
 

 


Node 서버 구성
대상:Node 서버 3대
 
아까 master 서버에서 별도 기록한 kubeadm join 명령을 수행하여 클러스터에 join 한다.
$ sudo kubeadm join 192.168.114.128:6443 --token pvpoff.3gi19fsxl8q6vq47 --discovery-token-ca-cert-hash sha256:e57e547d3697386005324524878f42b670db3f83227ff247464f4702fddf2d6
 
 

■ 점검
 
kubectl get node명령을 통해 모든 node가 READY 상태인지 확인한다.
ku# kubectl get nodes
NAME                    STATUS    ROLES     AGE       VERSION
k8s-master-ncl     Ready     master    19m       v1.11.2
kube-node001-ncl   Ready     <none>    1m        v1.11.2
kube-node002-ncl   Ready     <none>    1m        v1.11.2
kube-node003-ncl   Ready     <none>    1m        v1.11.2
 
 
 

 

'Kubernetes' 카테고리의 다른 글

Ingress에 Sticky Session 적용하기  (0) 2020.03.27

개요:
WAS에서 로그인 로직이 존재하는 경우, Ingress에서 Multi POD를 구성하면 로그인이 끊긴다.


원인:
Ingress는 기본적으로 Round-Robin으로 사용자 접속 정보를 Routing하므로, 사용자 세션 정보가 없는 POD로도 지속적으로 사용자 Request를 보낸다.

따라서 Session 정보가 없는 POD에 의한 처리가 될 경우 세션이 끊긴다.


해결책:
두가지 방안이 있다.

  1. Redis와 같은 Session Manager를 구성하여 Session Replication 하기
  2. Ingress에서 Sticky Session을 적용해서 Ingress Routing을 고정하기.
  
여기서는 Ingress에 Sticky Session을 적용하는 법을 가이드한다.


Ingress에 ticky session 적용 절차

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: nginx-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
    kubernetes.io/ingress.class: "nginx"
    nginx.ingress.kubernetes.io/affinity: "cookie"
    
nginx.ingress.kubernetes.io/session-cookie-hash: "sha1"
    
nginx.ingress.kubernetes.io/session-cookie-name: "route"

spec:
  rules:
  - host: test.skcc.com
    http:
      paths:
      - path: /
        backend:
          serviceName: svc-weblogic12c
          servicePort: 17001


 

 

 

'Kubernetes' 카테고리의 다른 글

Kubernetes 클러스터 구성 (1 Master + 3 Nodes)  (0) 2020.03.27

■ 개요:

이따금 Web이 무슨 제품인지 확인이 필요한데, 담당자가 부재중이거나 자산 시스템 접속권한이 없어서 확인이 불가능 할 때가 있습니다.

이러한 경우, Web서버의 HTTP헤더 정보를 통해 웹서버 또는 WAS가 어떤 제품인지 확인이 가능합니다.


■ 절차:

test11@localhost:~$ nslookup www.test1234.com <- 도메인 네임으로 IP 확인

Server:         127.0.0.1

Address:        127.0.0.1#53

 

Non-authoritative answer:

Name:   www.test1234.com

Address: 10.125.11.15 <- 사내구매시스템의 웹서버 IP요런거 임을 확인할 수 있음

 

test11@localhost:~$ telnet 10.125.11.15 80 <- 콘솔 접속

Trying 10.125.11.15...

Connected to 10.125.11.15.

Escape character is '^]'.

HEAD / HTTP/1.0 <- 헤더정보 읽어 오는 명령

 

HTTP/1.1 200 OK

Content-Length: 80

Content-Type: text/html

Last-Modified: Thu, 26 Feb 2009 09:16:02 GMT

Accept-Ranges: bytes

ETag: "58081d8f297c91:0"

Server: Microsoft-IIS/7.0 <- IIS를 쓰고 있네요.

Date: Tue, 28 Jan 2014 11:03:52 GMT

Connection: close

 

Connection closed by foreign host.

 

 

■ 개요:

유튜브의 최신 인기자료를 카테고리별로 가져와서, 내 사이트에 자동 업로드하는 절차 입니다.

가급적 기초적인 크롤링 명령은 알고 하시는게 좋습니다.



절차:

1. 크롤링 조건 정의


원하는 문자열 패턴과 조회수를 지정하여, 자동으로 검색 후 크롤링하는게 목적입니다.

아래의 경우는, 다음 3가지 조건을 만족하는 영상만 크롤링 하도록 정의하였습니다.

   가. "군대" 관련 영상

   나. 조회수 40만건 이상

   다. 최근 1개월내의 자료


※ time.sleep을 정의 하지 않을 경우, 과다한 크롤링 요청으로 인해 유튜브측에서 Block할 수 있으므로 주의 하기 바랍니다.


#########################################################################################################
# 군대 관련 영상
#########################################################################################################
BBS_CATEGORY="BBS_ARMY"
ARMY=[ '군대', '해병', '해군', '특전사', '육군', '공군', '공수부대' ] # 해당 문자열 패턴이 있는 영상만 검색

Limit=len(ARMY)
Gijun=400000 # 월간 40만건 이상 조회수 기록한 글만 크롤링
count=0

while count < Limit:
   KEY=str(str(ARMY[count]).encode('utf8')).replace("\\x","%").replace("b'","")
   URL="https://www.youtube.com/results?search_query="+KEY+"&sp=CAMSBAgEEAE%253D" # 월간
   func_get_movie_list(URL, BBS_CATEGORY, Gijun)
   time.sleep(7)
   count+=1


2. 영상 정보 가져오기


조건별로 정의된 유튜브 URL을 자동으로 분류해서 가져옵니다.

영상링크, 제목, 조회수, 썸네일주소, 영상코드가 포함되므로, 필요한 형태로 변형해서 사용가능합니다.


def func_get_movie_list(URL, BBS_CATEGORY, Gijun) :
    print("<<<<<<<<<<<<<<<<<<<<<<<" + BBS_CATEGORY +">>>>>>>>>>>>>>>>>>>>>>>>>>>>")

    pages = set()
    try:
        soup = BeautifulSoup(urlopen(URL), "html.parser", from_encoding='utf-8')
    except:
        print("[ERROR] soup 실행 실패")
        return
    LinkListRAW = soup.findAll(class_="yt-lockup-content")
    for LINK_RAW in LinkListRAW:
       parseLink=LINK_RAW.find("a")
       Link="https://www.youtube.com"+parseLink.get("href").replace("..","").replace("./", "", 1)
       Title=parseLink.get("title")
       RAW_Thumbnail="https://i.ytimg.com/vi/"+parseLink.get("href").replace("/watch?v=","")+"/hqdefault.jpg"
       MovieCode=parseLink.get("href").replace("/watch?v=","")
       ReadCountRaw=(LINK_RAW.find("ul").text)
       ReadCountRawPoint=(LINK_RAW.find("ul").text).find("수")+1
       ReadCount=(ReadCountRaw[ReadCountRawPoint:]).replace(" ","").replace(",","").replace("회","")
       print("[영상링크]" + Link)
       print("[제목]" + Title)
       print("[조회수]" + ReadCount)
       print("[썸네일주소]" + RAW_Thumbnail)
       print("[영상코드]" + MovieCode)
       try:
           Count=int(ReadCount)
       except:
           print("[ERROR] 게시물 리딩 갯수 조회 불가")
           Count=0
       if Count > Gijun:
           print("[INFO] 조회수"+str(Gijun)+" 넘으므로 업로드 대상") #
           UploadBBS(MovieCode, Title, RAW_Thumbnail, BBS_CATEGORY)
       else:
           print("[INFO] 처리 불가(조회수 적음) =>"+str(Count))


[실행화면]

[영상링크]https://www.youtube.com/watch?v=kINkPPx7Efk
[제목][이춘근의 국제정치 75회] ① 美 국민, 74%  주한미군 주둔 찬성
[조회수]122067
[썸네일주소]https://i.ytimg.com/vi/kINkPPx7Efk/hqdefault.jpg
[영상코드]kINkPPx7Efk
[INFO] 처리 불가(조회수 적음) =>122067
[영상링크]https://www.youtube.com/watch?v=5NR0qckPk1E
[제목][이춘근의 국제정치 75회] ② 방위비 분담금과 주한미군의 가치
[조회수]117454
[썸네일주소]https://i.ytimg.com/vi/5NR0qckPk1E/hqdefault.jpg
[영상코드]5NR0qckPk1E
[INFO] 처리 불가(조회수 적음) =>117454
[영상링크]https://www.youtube.com/watch?v=EYHQ6bAziXQ
[제목]2부 일본은 이미 미군 철수에 3단계 대비 중 / 미 육군은 훈련 못하는 주한 미군 철수도 고민  [세밀한안보] (2019.01.28)
[조회수]85377
[썸네일주소]https://i.ytimg.com/vi/EYHQ6bAziXQ/hqdefault.jpg
[영상코드]EYHQ6bAziXQ
[INFO] 처리 불가(조회수 적음) =>85377
[영상링크]https://www.youtube.com/watch?v=mHcAsGQnti4
[제목]미군, 북한 선제타격 준비! 브룩스 전 한미연합사령관 폭로! (전옥현 전 국정원 1차장) / 신의한수
[조회수]67698
[썸네일주소]https://i.ytimg.com/vi/mHcAsGQnti4/hqdefault.jpg
[영상코드]mHcAsGQnti4
[INFO] 처리 불가(조회수 적음) =>67698
[영상링크]https://www.youtube.com/watch?v=C4fDWtY0IU0
[제목]진짜 엄청난 미군 항공모함들!니미츠급에서 포드급(CVN-68 ~ CVN-78 )
[조회수]65734
[썸네일주소]https://i.ytimg.com/vi/C4fDWtY0IU0/hqdefault.jpg
[영상코드]C4fDWtY0IU0
[INFO] 처리 불가(조회수 적음) =>65734



3. 영상 정보 게시판에 업로드 하기


위 로직을 통해 데이터 크롤링까지 완료했습니다.

해당 데이터를 원하는 형태의 처리를 통해 DB 또는 게시물 형태로 변형하시면 얼마든지 재배포 가능합니다.



1. 현상:

Linux를 콘솔로 접속할때는 문제 없으나, 원격접속(Telnet, SSH)으로 접속시 한글이 깨지는 경우가 생길 수 있다.


2. 원인:

이 경우, 원인은 둘중 하나이다.

   가. 서버 측 인코딩 설정 문제

   나. 원격접속툴의 인코딩 설정 문제


3. 해결 방안


서버와 원격접속툴의 인코딩 설정을 UTF-8로 통일한다.

CharacterSet의 경우 어떤걸 사용해야 한다는 권고는 없으나, 가급적 i18n, profile, JVM옵션, Appl. Source까지

동일한 캐릭터셋으로 통일하는 것을 권고한다.

상이한 설정을 사용할 경우, 서비스 한글깨짐이나 첨부파일 한글명 깨짐등이 발생할 수 있다.


 가. 서버 측 인코딩 설정

[etc/sysconfig/i18n파일 수정]

LANG="ko_KR.UTF-8"

SUPPORTED="ko_KR.UTF-8:ko_KR:ko"


나 원격접속툴 인코딩 설정

+ Recent posts