카타코더 k8s - Running Stateful Services on Kubernetes

Jmnote (토론 | 기여)님의 2019년 3월 24일 (일) 03:21 판
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

1 개요[ | ]

카타코더 Kubernetes - Running Stateful Services on Kubernetes
카타코더 Kubernetes
# 🔗 제목
카타코더 Kubernetes/1 e
🡵 카타코더 k8s - Launch A Single Node Cluster
🡵 카타코더 k8s - Launch a multi-node cluster using Kubeadm
🡵 카타코더 k8s - Deploy Containers Using Kubectl
🡵 카타코더 k8s - Deploy Containers Using YAML
🡵 카타코더 k8s - Deploy Guestbook Web App Example
🡵 카타코더 k8s - Networking Introduction
🡵 카타코더 k8s - Create Ingress Routing
🡵 카타코더 k8s - Liveness and Readiness Healthchecks
🡵 카타코더 k8s - Getting Started With CRI-O and Kubeadm
🡵 카타코더 k8s - Running Stateful Services on Kubernetes

2 Deploy NFS Server[ | ]

master:~$ docker run -d --net=host --privileged --name nfs-server katacoda/contained-nfs-server:centos7  /exports/data-0001 /exports/data-0002
Unable to find image 'katacoda/contained-nfs-server:centos7' locally
centos7: Pulling from katacoda/contained-nfs-server
8d30e94188e7: Pull complete
2b2b27f1f462: Pull complete
133e63cf95fe: Pull complete
Digest: sha256:5f2ea4737fe27f26be5b5cabaa23e24180079a4dce8d5db235492ec48c5552d1
Status: Downloaded newer image for katacoda/contained-nfs-server:centos7
8ebc8aefd02c22505fa19a5ef5ce4777639586b3bd2267151a2422a9e066cc04

3 Deploy PV[ | ]

master:~$ cat nfs-0001.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
  name: nfs-0001
spec:
  capacity:
    storage: 2Gi
  accessModes:
    - ReadWriteOnce
    - ReadWriteMany
  persistentVolumeReclaimPolicy: Recycle
  nfs:
    server: 172.17.0.22
    path: /exports/data-0001
master:~$ cat nfs-0002.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
  name: nfs-0002
spec:
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteOnce
    - ReadWriteMany
  persistentVolumeReclaimPolicy: Recycle
  nfs:
    server: 172.17.0.22
    path: /exports/data-0002
master:~$ kubectl create -f nfs-0001.yaml
persistentvolume/nfs-0001 created
master:~$ kubectl create -f nfs-0002.yaml
persistentvolume/nfs-0002 created
master:~$ kubectl get pv
NAME       CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS      CLAIM STORAGECLASS   REASON    AGE
nfs-0001   2Gi        RWO,RWX        Recycle          Available                          7s
nfs-0002   5Gi        RWO,RWX        Recycle          Available                          4s

4 Deploy PVC[ | ]

master:~$ cat pvc-mysql.yaml
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: claim-mysql
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 3Gi
master:~$ cat pvc-http.yaml
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: claim-http
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
master:~$ kubectl create -f pvc-mysql.yaml
persistentvolumeclaim/claim-mysql created
master:~$ kubectl create -f pvc-http.yaml
persistentvolumeclaim/claim-http created
master:~$ kubectl get pvc
NAME          STATUS    VOLUME     CAPACITY   ACCESS MODES   STORAGECLASS AGE
claim-http    Bound     nfs-0001   2Gi        RWO,RWX 1s
claim-mysql   Bound     nfs-0002   5Gi        RWO,RWX 3s

5 Use Volume[ | ]

master:~$ cat pod-mysql.yaml
apiVersion: v1
kind: Pod
metadata:
  name: mysql
  labels:
    name: mysql
spec:
  containers:
  - name: mysql
    image: openshift/mysql-55-centos7
    env:
      - name: MYSQL_ROOT_PASSWORD
        value: yourpassword
      - name: MYSQL_USER
        value: wp_user
      - name: MYSQL_PASSWORD
        value: wp_pass
      - name: MYSQL_DATABASE
        value: wp_db
    ports:
      - containerPort: 3306
        name: mysql
    volumeMounts:
      - name: mysql-persistent-storage
        mountPath: /var/lib/mysql/data
  volumes:
    - name: mysql-persistent-storage
      persistentVolumeClaim:
        claimName: claim-mysql
master:~$ cat pod-www.yaml
apiVersion: v1
kind: Pod
metadata:
  name: www
  labels:
    name: www
spec:
  containers:
  - name: www
    image: nginx:alpine
    ports:
      - containerPort: 80
        name: www
    volumeMounts:
      - name: www-persistent-storage
        mountPath: /usr/share/nginx/html
  volumes:
    - name: www-persistent-storage
      persistentVolumeClaim:
        claimName: claim-http
master:~$ kubectl create -f pod-mysql.yaml
pod/mysql created
master:~$ kubectl create -f pod-www.yaml
pod/www created
master:~$ kubectl get pods
NAME      READY     STATUS    RESTARTS   AGE
mysql     1/1       Running   0          24s
www       1/1       Running   0          22s

6 Read/Write Data[ | ]

master:~$ docker exec -it nfs-server bash -c "echo 'Hello World' > /exports/data-0001/index.html"
master:~$ ip=$(kubectl get pod www -o yaml |grep podIP | awk '{split($0,a,":"); print a[2]}')
master:~$ echo $ip
10.32.0.5
master:~$ curl $ip
Hello World
master:~$ docker exec -it nfs-server bash -c "echo 'Hello NFS World' > /exports/data-0001/index.html"
master:~$ curl $ip
Hello NFS World

7 Recreate Pod[ | ]

master:~$ kubectl delete pod www
pod "www" deleted
master:~$ cat pod-www2.yaml
apiVersion: v1
kind: Pod
metadata:
  name: www2
  labels:
    name: www2
spec:
  containers:
  - name: www2
    image: nginx:alpine
    ports:
      - containerPort: 80
        name: www2
    volumeMounts:
      - name: www-persistent-storage
        mountPath: /usr/share/nginx/html
  volumes:
    - name: www-persistent-storage
      persistentVolumeClaim:
        claimName: claim-http
master:~$ kubectl create -f pod-www2.yaml
pod/www2 created
master:~$ ip=$(kubectl get pod www2 -o yaml |grep podIP | awk '{split($0,a,":"); print a[2]}')
master:~$ curl $ip
Hello NFS World
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}