(새 문서: ==개요== ;카타코더 Kubernetes - ;카타코더 Kubernetes - {{카타코더|Kubernetes|1}} ==== <source lang='console'> </source> <source lang='console'> </source>) |
|||
1번째 줄: | 1번째 줄: | ||
==개요== | ==개요== | ||
;카타코더 Kubernetes - | ;카타코더 Kubernetes - Networking Introduction | ||
{{카타코더|Kubernetes|1}} | {{카타코더|Kubernetes|1}} | ||
==== | ==Cluster IP== | ||
<source lang='console'> | <source lang='console'> | ||
master $ cat clusterip.yaml | |||
</source> | |||
<source lang='yaml'> | |||
apiVersion: v1 | |||
kind: Service | |||
metadata: | |||
name: webapp1-clusterip-svc | |||
labels: | |||
app: webapp1-clusterip | |||
spec: | |||
ports: | |||
- port: 80 | |||
selector: | |||
app: webapp1-clusterip | |||
--- | |||
apiVersion: extensions/v1beta1 | |||
kind: Deployment | |||
metadata: | |||
name: webapp1-clusterip-deployment | |||
spec: | |||
replicas: 2 | |||
template: | |||
metadata: | |||
labels: | |||
app: webapp1-clusterip | |||
spec: | |||
containers: | |||
- name: webapp1-clusterip-pod | |||
image: katacoda/docker-http-server:latest | |||
ports: | |||
- containerPort: 80 | |||
--- | |||
</source> | |||
<source lang='console'> | |||
master $ kubectl apply -f clusterip.yaml | |||
service/webapp1-clusterip-svc created | |||
deployment.extensions/webapp1-clusterip-deployment created | |||
</source> | |||
<source lang='console'> | |||
master $ kubectl get pods | |||
NAME READY STATUS RESTARTS AGE | |||
webapp1-clusterip-deployment-7fd8b9674b-b9dns 1/1 Running 0 22s | |||
webapp1-clusterip-deployment-7fd8b9674b-zdqbq 1/1 Running 0 22s | |||
</source> | |||
<source lang='console'> | |||
master $ kubectl get svc | |||
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE | |||
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 1m | |||
webapp1-clusterip-svc ClusterIP 10.98.44.183 <none> 80/TCP 31s | |||
</source> | |||
<source lang='console'> | |||
master $ kubectl describe svc/webapp1-clusterip-svc | |||
Name: webapp1-clusterip-svc | |||
Namespace: default | |||
Labels: app=webapp1-clusterip | |||
Annotations: kubectl.kubernetes.io/last-applied-configuration={"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"labels":{"app":"webapp1-clusterip"},"name":"webapp1-clusterip-svc","namespace":"defau... | |||
Selector: app=webapp1-clusterip | |||
Type: ClusterIP | |||
IP: 10.98.44.183 | |||
Port: <unset> 80/TCP | |||
TargetPort: 80/TCP | |||
Endpoints: 10.32.0.2:80,10.32.0.3:80 | |||
Session Affinity: None | |||
Events: <none> | |||
</source> | |||
<source lang='console'> | |||
master $ export CLUSTER_IP=$(kubectl get services/webapp1-clusterip-svc-o go-template='{{(index .spec.clusterIP)}}') | |||
master $ echo CLUSTER_IP=$CLUSTER_IP | |||
CLUSTER_IP=10.98.44.183 | |||
</source> | |||
<source lang='console'> | |||
master $ curl $CLUSTER_IP:80 | |||
<h1>This request was processed by host: webapp1-clusterip-deployment-7fd8b9674b-b9dns</h1> | |||
</source> | |||
<source lang='console'> | |||
master $ curl $CLUSTER_IP:80 | |||
<h1>This request was processed by host: webapp1-clusterip-deployment-7fd8b9674b-b9dns</h1> | |||
</source> | |||
<source lang='console'> | |||
master $ curl $CLUSTER_IP:80 | |||
<h1>This request was processed by host: webapp1-clusterip-deployment-7fd8b9674b-b9dns</h1> | |||
</source> | |||
<source lang='console'> | |||
master $ curl $CLUSTER_IP:80 | |||
<h1>This request was processed by host: webapp1-clusterip-deployment-7fd8b9674b-zdqbq</h1> | |||
</source> | |||
<source lang='console'> | |||
master $ curl $CLUSTER_IP:80 | |||
<h1>This request was processed by host: webapp1-clusterip-deployment-7fd8b9674b-zdqbq</h1> | |||
</source> | |||
<source lang='console'> | |||
master $ curl $CLUSTER_IP:80 | |||
<h1>This request was processed by host: webapp1-clusterip-deployment-7fd8b9674b-zdqbq</h1> | |||
</source> | |||
<source lang='console'> | |||
master $ curl $CLUSTER_IP:80 | |||
<h1>This request was processed by host: webapp1-clusterip-deployment-7fd8b9674b-b9dns</h1> | |||
</source> | |||
==Target Port== | |||
<source lang='console'> | |||
master $ cat clusterip-target.yaml | |||
</source> | |||
<source lang='yaml'> | |||
apiVersion: v1 | |||
kind: Service | |||
metadata: | |||
name: webapp1-clusterip-targetport-svc | |||
labels: | |||
app: webapp1-clusterip-targetport | |||
spec: | |||
ports: | |||
- port: 8080 | |||
targetPort: 80 | |||
selector: | |||
app: webapp1-clusterip-targetport | |||
--- | |||
apiVersion: extensions/v1beta1 | |||
kind: Deployment | |||
metadata: | |||
name: webapp1-clusterip-targetport-deployment | |||
spec: | |||
replicas: 2 | |||
template: | |||
metadata: | |||
labels: | |||
app: webapp1-clusterip-targetport | |||
spec: | |||
containers: | |||
- name: webapp1-clusterip-targetport-pod | |||
image: katacoda/docker-http-server:latest | |||
ports: | |||
- containerPort: 80 | |||
--- | |||
</source> | |||
<source lang='console'> | |||
master $ kubectl apply -f clusterip-target.yaml | |||
service/webapp1-clusterip-targetport-svc created | |||
deployment.extensions/webapp1-clusterip-targetport-deployment created | |||
</source> | |||
<source lang='console'> | |||
master $ kubectl get svc | |||
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE | |||
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 3m | |||
webapp1-clusterip-svc ClusterIP 10.98.44.183 <none> 80/TCP 3m | |||
webapp1-clusterip-targetport-svc ClusterIP 10.105.237.185 <none> 8080/TCP 16s | |||
</source> | |||
<source lang='console'> | |||
master $ kubectl describe svc/webapp1-clusterip-targetport-svc | |||
Name: webapp1-clusterip-targetport-svc | |||
Namespace: default | |||
Labels: app=webapp1-clusterip-targetport | |||
Annotations: kubectl.kubernetes.io/last-applied-configuration={"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"labels":{"app":"webapp1-clusterip-targetport"},"name":"webapp1-clusterip-targetport-s... | |||
Selector: app=webapp1-clusterip-targetport | |||
Type: ClusterIP | |||
IP: 10.105.237.185 | |||
Port: <unset> 8080/TCP | |||
TargetPort: 80/TCP | |||
Endpoints: 10.32.0.6:80,10.32.0.7:80 | |||
Session Affinity: None | |||
Events: <none> | |||
</source> | |||
<source lang='console'> | |||
master $ export CLUSTER_IP=$(kubectl get services/webapp1-clusterip-targetport-svc -o go-template='{{(index .spec.clusterIP)}}') | |||
master $ echo CLUSTER_IP=$CLUSTER_IP | |||
CLUSTER_IP=10.105.237.185 | |||
</source> | |||
<source lang='console'> | |||
master $ curl $CLUSTER_IP:8080 | |||
<h1>This request was processed by host: webapp1-clusterip-targetport-deployment-ffdbb7558-pdc9j</h1> | |||
</source> | |||
<source lang='console'> | |||
master $ curl $CLUSTER_IP:8080 | |||
<h1>This request was processed by host: webapp1-clusterip-targetport-deployment-ffdbb7558-pdc9j</h1> | |||
</source> | |||
<source lang='console'> | |||
master $ curl $CLUSTER_IP:8080 | |||
<h1>This request was processed by host: webapp1-clusterip-targetport-deployment-ffdbb7558-wtvs7</h1> | |||
</source> | |||
<source lang='console'> | |||
master $ curl $CLUSTER_IP:8080 | |||
<h1>This request was processed by host: webapp1-clusterip-targetport-deployment-ffdbb7558-wtvs7</h1> | |||
</source> | |||
<source lang='console'> | |||
master $ curl $CLUSTER_IP:8080 | |||
<h1>This request was processed by host: webapp1-clusterip-targetport-deployment-ffdbb7558-pdc9j</h1> | |||
</source> | |||
==NodePort== | |||
<source lang='console'> | |||
master $ cat nodeport.yaml | |||
</source> | |||
<source lang='yaml'> | |||
apiVersion: v1 | |||
kind: Service | |||
metadata: | |||
name: webapp1-nodeport-svc | |||
labels: | |||
app: webapp1-nodeport | |||
spec: | |||
type: NodePort | |||
ports: | |||
- port: 80 | |||
nodePort: 30080 | |||
selector: | |||
app: webapp1-nodeport | |||
--- | |||
apiVersion: extensions/v1beta1 | |||
kind: Deployment | |||
metadata: | |||
name: webapp1-nodeport-deployment | |||
spec: | |||
replicas: 2 | |||
template: | |||
metadata: | |||
labels: | |||
app: webapp1-nodeport | |||
spec: | |||
containers: | |||
- name: webapp1-nodeport-pod | |||
image: katacoda/docker-http-server:latest | |||
ports: | |||
- containerPort: 80 | |||
--- | |||
</source> | |||
<source lang='console'> | |||
master $ kubectl apply -f nodeport.yaml | |||
service/webapp1-nodeport-svc created | |||
deployment.extensions/webapp1-nodeport-deployment created | |||
</source> | |||
<source lang='console'> | |||
master $ kubectl get svc | |||
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE | |||
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 6m | |||
webapp1-clusterip-svc ClusterIP 10.98.44.183 <none> 80/TCP 6m | |||
webapp1-clusterip-targetport-svc ClusterIP 10.105.237.185 <none> 8080/TCP 3m | |||
webapp1-nodeport-svc NodePort 10.97.69.120 <none> 80:30080/TCP 20s | |||
</source> | |||
<source lang='console'> | |||
master $ kubectl describe svc/webapp1-nodeport-svc | |||
Name: webapp1-nodeport-svc | |||
Namespace: default | |||
Labels: app=webapp1-nodeport | |||
Annotations: kubectl.kubernetes.io/last-applied-configuration={"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"labels":{"app":"webapp1-nodeport"},"name":"webapp1-nodeport-svc","namespace":"default... | |||
Selector: app=webapp1-nodeport | |||
Type: NodePort | |||
IP: 10.97.69.120 | |||
Port: <unset> 80/TCP | |||
TargetPort: 80/TCP | |||
NodePort: <unset> 30080/TCP | |||
Endpoints: 10.32.0.8:80,10.32.0.9:80 | |||
Session Affinity: None | |||
External Traffic Policy: Cluster | |||
Events: <none> | |||
</source> | |||
<source lang='console'> | |||
master $ curl 172.17.0.19:30080 | |||
<h1>This request was processed by host: webapp1-nodeport-deployment-785989576b-j5fc6</h1> | |||
</source> | |||
<source lang='console'> | |||
master $ curl 172.17.0.19:30080 | |||
<h1>This request was processed by host: webapp1-nodeport-deployment-785989576b-j5fc6</h1> | |||
</source> | |||
<source lang='console'> | |||
master $ curl 172.17.0.19:30080 | |||
<h1>This request was processed by host: webapp1-nodeport-deployment-785989576b-gcwgb</h1> | |||
</source> | |||
<source lang='console'> | |||
master $ curl 172.17.0.19:30080 | |||
<h1>This request was processed by host: webapp1-nodeport-deployment-785989576b-j5fc6</h1> | |||
</source> | |||
==External IPs== | |||
<source lang='console'> | |||
master $ cat externalip.yaml | |||
</source> | |||
<source lang='yaml'> | |||
apiVersion: v1 | |||
kind: Service | |||
metadata: | |||
name: webapp1-externalip-svc | |||
labels: | |||
app: webapp1-externalip | |||
spec: | |||
ports: | |||
- port: 80 | |||
externalIPs: | |||
- HOSTIP | |||
selector: | |||
app: webapp1-externalip | |||
--- | |||
apiVersion: extensions/v1beta1 | |||
kind: Deployment | |||
metadata: | |||
name: webapp1-externalip-deployment | |||
spec: | |||
replicas: 2 | |||
template: | |||
metadata: | |||
labels: | |||
app: webapp1-externalip | |||
spec: | |||
containers: | |||
- name: webapp1-externalip-pod | |||
image: katacoda/docker-http-server:latest | |||
ports: | |||
- containerPort: 80 | |||
--- | |||
</source> | |||
<source lang='console'> | |||
master $ sed -i 's/HOSTIP/172.17.0.19/g' externalip.yaml | |||
master $ kubectl apply -f externalip.yaml | |||
service/webapp1-externalip-svc created | |||
deployment.extensions/webapp1-externalip-deployment created | |||
</source> | |||
<source lang='console'> | |||
master $ kubectl get svc | |||
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE | |||
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 9m | |||
webapp1-clusterip-svc ClusterIP 10.98.44.183 <none> 80/TCP 8m | |||
webapp1-clusterip-targetport-svc ClusterIP 10.105.237.185 <none> 8080/TCP 6m | |||
webapp1-externalip-svc ClusterIP 10.109.41.233 172.17.0.19 80/TCP 21s | |||
webapp1-nodeport-svc NodePort 10.97.69.120 <none> 80:30080/TCP 2m | |||
</source> | |||
<source lang='console'> | |||
master $ kubectl describe svc/webapp1-externalip-svc | |||
Name: webapp1-externalip-svc | |||
Namespace: default | |||
Labels: app=webapp1-externalip | |||
Annotations: kubectl.kubernetes.io/last-applied-configuration={"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"labels":{"app":"webapp1-externalip"},"name":"webapp1-externalip-svc","namespace":"def... | |||
Selector: app=webapp1-externalip | |||
Type: ClusterIP | |||
IP: 10.109.41.233 | |||
External IPs: 172.17.0.19 | |||
Port: <unset> 80/TCP | |||
TargetPort: 80/TCP | |||
Endpoints: 10.32.0.10:80,10.32.0.11:80 | |||
Session Affinity: None | |||
Events: <none> | |||
</source> | |||
<source lang='console'> | |||
master $ curl 172.17.0.19 | |||
<h1>This request was processed by host: webapp1-externalip-deployment-bdf9688c4-chw4b</h1> | |||
</source> | |||
<source lang='console'> | |||
master $ curl 172.17.0.19 | |||
<h1>This request was processed by host: webapp1-externalip-deployment-bdf9688c4-8p4fg</h1> | |||
</source> | |||
<source lang='console'> | |||
master $ curl 172.17.0.19 | |||
<h1>This request was processed by host: webapp1-externalip-deployment-bdf9688c4-chw4b</h1> | |||
</source> | |||
==Load Balancer== | |||
<source lang='console'> | |||
master $ cat cloudprovider.yaml | |||
</source> | |||
<source lang='yaml'> | |||
apiVersion: extensions/v1beta1 | |||
kind: DaemonSet | |||
metadata: | |||
name: kube-keepalived-vip | |||
namespace: kube-system | |||
spec: | |||
template: | |||
metadata: | |||
labels: | |||
name: kube-keepalived-vip | |||
spec: | |||
hostNetwork: true | |||
containers: | |||
- image: gcr.io/google_containers/kube-keepalived-vip:0.9 | |||
name: kube-keepalived-vip | |||
imagePullPolicy: Always | |||
securityContext: | |||
privileged: true | |||
volumeMounts: | |||
- mountPath: /lib/modules | |||
name: modules | |||
readOnly: true | |||
- mountPath: /dev | |||
name: dev | |||
# use downward API | |||
env: | |||
- name: POD_NAME | |||
valueFrom: | |||
fieldRef: | |||
fieldPath: metadata.name | |||
- name: POD_NAMESPACE | |||
valueFrom: | |||
fieldRef: | |||
fieldPath: metadata.namespace | |||
# to use unicast | |||
args: | |||
- --services-configmap=kube-system/vip-configmap | |||
# unicast uses the ip of the nodes instead of multicast | |||
# this is useful if running in cloud providers (like AWS) | |||
#- --use-unicast=true | |||
volumes: | |||
- name: modules | |||
hostPath: | |||
path: /lib/modules | |||
- name: dev | |||
hostPath: | |||
path: /dev | |||
nodeSelector: | |||
# type: worker # adjust this to match your worker nodes | |||
--- | |||
## We also create an empty ConfigMap to hold our config | |||
apiVersion: v1 | |||
kind: ConfigMap | |||
metadata: | |||
name: vip-configmap | |||
namespace: kube-system | |||
data: | |||
--- | |||
apiVersion: apps/v1beta1 | |||
kind: Deployment | |||
metadata: | |||
labels: | |||
app: keepalived-cloud-provider | |||
name: keepalived-cloud-provider | |||
namespace: kube-system | |||
spec: | |||
replicas: 1 | |||
revisionHistoryLimit: 2 | |||
selector: | |||
matchLabels: | |||
app: keepalived-cloud-provider | |||
strategy: | |||
type: RollingUpdate | |||
template: | |||
metadata: | |||
annotations: | |||
scheduler.alpha.kubernetes.io/critical-pod: "" | |||
scheduler.alpha.kubernetes.io/tolerations: '[{"key":"CriticalAddonsOnly", "operator":"Exists"}]' | |||
labels: | |||
app: keepalived-cloud-provider | |||
spec: | |||
containers: | |||
- name: keepalived-cloud-provider | |||
image: quay.io/munnerz/keepalived-cloud-provider:0.0.1 | |||
imagePullPolicy: IfNotPresent | |||
env: | |||
- name: KEEPALIVED_NAMESPACE | |||
value: kube-system | |||
- name: KEEPALIVED_CONFIG_MAP | |||
value: vip-configmap | |||
- name: KEEPALIVED_SERVICE_CIDR | |||
value: 10.10.0.0/26 # pick a CIDR that is explicitly reservedfor keepalived | |||
volumeMounts: | |||
- name: certs | |||
mountPath: /etc/ssl/certs | |||
resources: | |||
requests: | |||
cpu: 200m | |||
livenessProbe: | |||
httpGet: | |||
path: /healthz | |||
port: 10252 | |||
host: 127.0.0.1 | |||
initialDelaySeconds: 15 | |||
timeoutSeconds: 15 | |||
failureThreshold: 8 | |||
volumes: | |||
- name: certs | |||
hostPath: | |||
path: /etc/ssl/certs | |||
</source> | |||
<source lang='console'> | |||
master $ kubectl apply -f cloudprovider.yaml | |||
daemonset.extensions/kube-keepalived-vip created | |||
configmap/vip-configmap created | |||
deployment.apps/keepalived-cloud-provider created | |||
</source> | |||
<source lang='console'> | |||
master $ kubectl get pods -n kube-system | |||
NAME READY STATUS RESTARTS AGE | |||
coredns-78fcdf6894-d4cwq 1/1 Running 0 11m | |||
coredns-78fcdf6894-j2wc5 1/1 Running 0 11m | |||
etcd-master 1/1 Running 0 10m | |||
keepalived-cloud-provider-fb7465d76-jxckr 1/1 Running 0 9s | |||
kube-apiserver-master 1/1 Running 0 10m | |||
kube-controller-manager-master 1/1 Running 0 9m | |||
kube-keepalived-vip-2rdt2 1/1 Running 0 9s | |||
kube-proxy-rpmm5 1/1 Running 0 11m | |||
kube-scheduler-master 1/1 Running 0 10m | |||
weave-net-6ppzr 2/2 Running 1 11m | |||
</source> | |||
<source lang='console'> | |||
master $ cat loadbalancer.yaml | |||
</source> | |||
<source lang='yaml'> | |||
apiVersion: v1 | |||
kind: Service | |||
metadata: | |||
name: webapp1-loadbalancer-svc | |||
labels: | |||
app: webapp1-loadbalancer | |||
spec: | |||
type: LoadBalancer | |||
ports: | |||
- port: 80 | |||
selector: | |||
app: webapp1-loadbalancer | |||
--- | |||
apiVersion: extensions/v1beta1 | |||
kind: Deployment | |||
metadata: | |||
name: webapp1-loadbalancer-deployment | |||
spec: | |||
replicas: 2 | |||
template: | |||
metadata: | |||
labels: | |||
app: webapp1-loadbalancer | |||
spec: | |||
containers: | |||
- name: webapp1-loadbalancer-pod | |||
image: katacoda/docker-http-server:latest | |||
ports: | |||
- containerPort: 80 | |||
--- | |||
</source> | |||
<source lang='console'> | |||
master $ kubectl apply -f loadbalancer.yaml | |||
service/webapp1-loadbalancer-svc created | |||
deployment.extensions/webapp1-loadbalancer-deployment created | |||
</source> | |||
<source lang='console'> | |||
master $ kubectl get svc | |||
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE | |||
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 12m | |||
webapp1-clusterip-svc ClusterIP 10.98.44.183 <none> 80/TCP 11m | |||
webapp1-clusterip-targetport-svc ClusterIP 10.105.237.185 <none> 8080/TCP 8m | |||
webapp1-externalip-svc ClusterIP 10.109.41.233 172.17.0.19 80/TCP 2m | |||
webapp1-loadbalancer-svc LoadBalancer 10.110.83.174 10.10.0.1 80:31235/TCP 8s | |||
webapp1-nodeport-svc NodePort 10.97.69.120 <none> 80:30080/TCP 5m | |||
</source> | |||
<source lang='console'> | |||
master $ kubectl describe svc/webapp1-loadbalancer-svc | |||
Name: webapp1-loadbalancer-svc | |||
Namespace: default | |||
Labels: app=webapp1-loadbalancer | |||
Annotations: kubectl.kubernetes.io/last-applied-configuration={"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"labels":{"app":"webapp1-loadbalancer"},"name":"webapp1-loadbalancer-svc","namespace":... | |||
Selector: app=webapp1-loadbalancer | |||
Type: LoadBalancer | |||
IP: 10.110.83.174 | |||
LoadBalancer Ingress: 10.10.0.1 | |||
Port: <unset> 80/TCP | |||
TargetPort: 80/TCP | |||
NodePort: <unset> 31235/TCP | |||
Endpoints: 10.32.0.13:80,10.32.0.14:80 | |||
Session Affinity: None | |||
External Traffic Policy: Cluster | |||
Events: | |||
Type Reason Age From Message | |||
---- ------ ---- ---- ------- | |||
Normal CreatingLoadBalancer 19s service-controller Creating loadbalancer | |||
Normal CreatedLoadBalancer 19s service-controller Created load balancer | |||
</source> | |||
<source lang='console'> | |||
master $ export LoadBalancerIP=$(kubectl get services/webapp1-loadbalancer-svc -o go-template='{{(index .status.loadBalancer.ingress 0).ip}}') | |||
master $ echo LoadBalancerIP=$LoadBalancerIP | |||
LoadBalancerIP=10.10.0.1 | |||
</source> | |||
<source lang='console'> | |||
master $ curl $LoadBalancerIP | |||
<h1>This request was processed by host: webapp1-loadbalancer-deployment-69b9f76fd6-zwgvz</h1> | |||
</source> | |||
<source lang='console'> | |||
master $ curl $LoadBalancerIP | |||
<h1>This request was processed by host: webapp1-loadbalancer-deployment-69b9f76fd6-wr847</h1> | |||
</source> | </source> | ||
<source lang='console'> | <source lang='console'> | ||
master $ curl $LoadBalancerIP | |||
<h1>This request was processed by host: webapp1-loadbalancer-deployment-69b9f76fd6-zwgvz</h1> | |||
</source> | </source> |
2019년 3월 24일 (일) 01:05 판
1 개요
- 카타코더 Kubernetes - Networking Introduction
2 Cluster IP
Console
Copy
master $ cat clusterip.yaml
yaml
Copy
apiVersion: v1
kind: Service
metadata:
name: webapp1-clusterip-svc
labels:
app: webapp1-clusterip
spec:
ports:
- port: 80
selector:
app: webapp1-clusterip
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: webapp1-clusterip-deployment
spec:
replicas: 2
template:
metadata:
labels:
app: webapp1-clusterip
spec:
containers:
- name: webapp1-clusterip-pod
image: katacoda/docker-http-server:latest
ports:
- containerPort: 80
---
Console
Copy
master $ kubectl apply -f clusterip.yaml
service/webapp1-clusterip-svc created
deployment.extensions/webapp1-clusterip-deployment created
Console
Copy
master $ kubectl get pods
NAME READY STATUS RESTARTS AGE
webapp1-clusterip-deployment-7fd8b9674b-b9dns 1/1 Running 0 22s
webapp1-clusterip-deployment-7fd8b9674b-zdqbq 1/1 Running 0 22s
Console
Copy
master $ kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 1m
webapp1-clusterip-svc ClusterIP 10.98.44.183 <none> 80/TCP 31s
Console
Copy
master $ kubectl describe svc/webapp1-clusterip-svc
Name: webapp1-clusterip-svc
Namespace: default
Labels: app=webapp1-clusterip
Annotations: kubectl.kubernetes.io/last-applied-configuration={"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"labels":{"app":"webapp1-clusterip"},"name":"webapp1-clusterip-svc","namespace":"defau...
Selector: app=webapp1-clusterip
Type: ClusterIP
IP: 10.98.44.183
Port: <unset> 80/TCP
TargetPort: 80/TCP
Endpoints: 10.32.0.2:80,10.32.0.3:80
Session Affinity: None
Events: <none>
Console
Copy
master $ export CLUSTER_IP=$(kubectl get services/webapp1-clusterip-svc-o go-template='{{(index .spec.clusterIP)}}')
master $ echo CLUSTER_IP=$CLUSTER_IP
CLUSTER_IP=10.98.44.183
Console
Copy
master $ curl $CLUSTER_IP:80
<h1>This request was processed by host: webapp1-clusterip-deployment-7fd8b9674b-b9dns</h1>
Console
Copy
master $ curl $CLUSTER_IP:80
<h1>This request was processed by host: webapp1-clusterip-deployment-7fd8b9674b-b9dns</h1>
Console
Copy
master $ curl $CLUSTER_IP:80
<h1>This request was processed by host: webapp1-clusterip-deployment-7fd8b9674b-b9dns</h1>
Console
Copy
master $ curl $CLUSTER_IP:80
<h1>This request was processed by host: webapp1-clusterip-deployment-7fd8b9674b-zdqbq</h1>
Console
Copy
master $ curl $CLUSTER_IP:80
<h1>This request was processed by host: webapp1-clusterip-deployment-7fd8b9674b-zdqbq</h1>
Console
Copy
master $ curl $CLUSTER_IP:80
<h1>This request was processed by host: webapp1-clusterip-deployment-7fd8b9674b-zdqbq</h1>
Console
Copy
master $ curl $CLUSTER_IP:80
<h1>This request was processed by host: webapp1-clusterip-deployment-7fd8b9674b-b9dns</h1>
3 Target Port
Console
Copy
master $ cat clusterip-target.yaml
yaml
Copy
apiVersion: v1
kind: Service
metadata:
name: webapp1-clusterip-targetport-svc
labels:
app: webapp1-clusterip-targetport
spec:
ports:
- port: 8080
targetPort: 80
selector:
app: webapp1-clusterip-targetport
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: webapp1-clusterip-targetport-deployment
spec:
replicas: 2
template:
metadata:
labels:
app: webapp1-clusterip-targetport
spec:
containers:
- name: webapp1-clusterip-targetport-pod
image: katacoda/docker-http-server:latest
ports:
- containerPort: 80
---
Console
Copy
master $ kubectl apply -f clusterip-target.yaml
service/webapp1-clusterip-targetport-svc created
deployment.extensions/webapp1-clusterip-targetport-deployment created
Console
Copy
master $ kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 3m
webapp1-clusterip-svc ClusterIP 10.98.44.183 <none> 80/TCP 3m
webapp1-clusterip-targetport-svc ClusterIP 10.105.237.185 <none> 8080/TCP 16s
Console
Copy
master $ kubectl describe svc/webapp1-clusterip-targetport-svc
Name: webapp1-clusterip-targetport-svc
Namespace: default
Labels: app=webapp1-clusterip-targetport
Annotations: kubectl.kubernetes.io/last-applied-configuration={"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"labels":{"app":"webapp1-clusterip-targetport"},"name":"webapp1-clusterip-targetport-s...
Selector: app=webapp1-clusterip-targetport
Type: ClusterIP
IP: 10.105.237.185
Port: <unset> 8080/TCP
TargetPort: 80/TCP
Endpoints: 10.32.0.6:80,10.32.0.7:80
Session Affinity: None
Events: <none>
Console
Copy
master $ export CLUSTER_IP=$(kubectl get services/webapp1-clusterip-targetport-svc -o go-template='{{(index .spec.clusterIP)}}')
master $ echo CLUSTER_IP=$CLUSTER_IP
CLUSTER_IP=10.105.237.185
Console
Copy
master $ curl $CLUSTER_IP:8080
<h1>This request was processed by host: webapp1-clusterip-targetport-deployment-ffdbb7558-pdc9j</h1>
Console
Copy
master $ curl $CLUSTER_IP:8080
<h1>This request was processed by host: webapp1-clusterip-targetport-deployment-ffdbb7558-pdc9j</h1>
Console
Copy
master $ curl $CLUSTER_IP:8080
<h1>This request was processed by host: webapp1-clusterip-targetport-deployment-ffdbb7558-wtvs7</h1>
Console
Copy
master $ curl $CLUSTER_IP:8080
<h1>This request was processed by host: webapp1-clusterip-targetport-deployment-ffdbb7558-wtvs7</h1>
Console
Copy
master $ curl $CLUSTER_IP:8080
<h1>This request was processed by host: webapp1-clusterip-targetport-deployment-ffdbb7558-pdc9j</h1>
4 NodePort
Console
Copy
master $ cat nodeport.yaml
yaml
Copy
apiVersion: v1
kind: Service
metadata:
name: webapp1-nodeport-svc
labels:
app: webapp1-nodeport
spec:
type: NodePort
ports:
- port: 80
nodePort: 30080
selector:
app: webapp1-nodeport
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: webapp1-nodeport-deployment
spec:
replicas: 2
template:
metadata:
labels:
app: webapp1-nodeport
spec:
containers:
- name: webapp1-nodeport-pod
image: katacoda/docker-http-server:latest
ports:
- containerPort: 80
---
Console
Copy
master $ kubectl apply -f nodeport.yaml
service/webapp1-nodeport-svc created
deployment.extensions/webapp1-nodeport-deployment created
Console
Copy
master $ kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 6m
webapp1-clusterip-svc ClusterIP 10.98.44.183 <none> 80/TCP 6m
webapp1-clusterip-targetport-svc ClusterIP 10.105.237.185 <none> 8080/TCP 3m
webapp1-nodeport-svc NodePort 10.97.69.120 <none> 80:30080/TCP 20s
Console
Copy
master $ kubectl describe svc/webapp1-nodeport-svc
Name: webapp1-nodeport-svc
Namespace: default
Labels: app=webapp1-nodeport
Annotations: kubectl.kubernetes.io/last-applied-configuration={"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"labels":{"app":"webapp1-nodeport"},"name":"webapp1-nodeport-svc","namespace":"default...
Selector: app=webapp1-nodeport
Type: NodePort
IP: 10.97.69.120
Port: <unset> 80/TCP
TargetPort: 80/TCP
NodePort: <unset> 30080/TCP
Endpoints: 10.32.0.8:80,10.32.0.9:80
Session Affinity: None
External Traffic Policy: Cluster
Events: <none>
Console
Copy
master $ curl 172.17.0.19:30080
<h1>This request was processed by host: webapp1-nodeport-deployment-785989576b-j5fc6</h1>
Console
Copy
master $ curl 172.17.0.19:30080
<h1>This request was processed by host: webapp1-nodeport-deployment-785989576b-j5fc6</h1>
Console
Copy
master $ curl 172.17.0.19:30080
<h1>This request was processed by host: webapp1-nodeport-deployment-785989576b-gcwgb</h1>
Console
Copy
master $ curl 172.17.0.19:30080
<h1>This request was processed by host: webapp1-nodeport-deployment-785989576b-j5fc6</h1>
5 External IPs
Console
Copy
master $ cat externalip.yaml
yaml
Copy
apiVersion: v1
kind: Service
metadata:
name: webapp1-externalip-svc
labels:
app: webapp1-externalip
spec:
ports:
- port: 80
externalIPs:
- HOSTIP
selector:
app: webapp1-externalip
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: webapp1-externalip-deployment
spec:
replicas: 2
template:
metadata:
labels:
app: webapp1-externalip
spec:
containers:
- name: webapp1-externalip-pod
image: katacoda/docker-http-server:latest
ports:
- containerPort: 80
---
Console
Copy
master $ sed -i 's/HOSTIP/172.17.0.19/g' externalip.yaml
master $ kubectl apply -f externalip.yaml
service/webapp1-externalip-svc created
deployment.extensions/webapp1-externalip-deployment created
Console
Copy
master $ kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 9m
webapp1-clusterip-svc ClusterIP 10.98.44.183 <none> 80/TCP 8m
webapp1-clusterip-targetport-svc ClusterIP 10.105.237.185 <none> 8080/TCP 6m
webapp1-externalip-svc ClusterIP 10.109.41.233 172.17.0.19 80/TCP 21s
webapp1-nodeport-svc NodePort 10.97.69.120 <none> 80:30080/TCP 2m
Console
Copy
master $ kubectl describe svc/webapp1-externalip-svc
Name: webapp1-externalip-svc
Namespace: default
Labels: app=webapp1-externalip
Annotations: kubectl.kubernetes.io/last-applied-configuration={"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"labels":{"app":"webapp1-externalip"},"name":"webapp1-externalip-svc","namespace":"def...
Selector: app=webapp1-externalip
Type: ClusterIP
IP: 10.109.41.233
External IPs: 172.17.0.19
Port: <unset> 80/TCP
TargetPort: 80/TCP
Endpoints: 10.32.0.10:80,10.32.0.11:80
Session Affinity: None
Events: <none>
Console
Copy
master $ curl 172.17.0.19
<h1>This request was processed by host: webapp1-externalip-deployment-bdf9688c4-chw4b</h1>
Console
Copy
master $ curl 172.17.0.19
<h1>This request was processed by host: webapp1-externalip-deployment-bdf9688c4-8p4fg</h1>
Console
Copy
master $ curl 172.17.0.19
<h1>This request was processed by host: webapp1-externalip-deployment-bdf9688c4-chw4b</h1>
6 Load Balancer
Console
Copy
master $ cat cloudprovider.yaml
yaml
Copy
apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
name: kube-keepalived-vip
namespace: kube-system
spec:
template:
metadata:
labels:
name: kube-keepalived-vip
spec:
hostNetwork: true
containers:
- image: gcr.io/google_containers/kube-keepalived-vip:0.9
name: kube-keepalived-vip
imagePullPolicy: Always
securityContext:
privileged: true
volumeMounts:
- mountPath: /lib/modules
name: modules
readOnly: true
- mountPath: /dev
name: dev
# use downward API
env:
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
# to use unicast
args:
- --services-configmap=kube-system/vip-configmap
# unicast uses the ip of the nodes instead of multicast
# this is useful if running in cloud providers (like AWS)
#- --use-unicast=true
volumes:
- name: modules
hostPath:
path: /lib/modules
- name: dev
hostPath:
path: /dev
nodeSelector:
# type: worker # adjust this to match your worker nodes
---
## We also create an empty ConfigMap to hold our config
apiVersion: v1
kind: ConfigMap
metadata:
name: vip-configmap
namespace: kube-system
data:
---
apiVersion: apps/v1beta1
kind: Deployment
metadata:
labels:
app: keepalived-cloud-provider
name: keepalived-cloud-provider
namespace: kube-system
spec:
replicas: 1
revisionHistoryLimit: 2
selector:
matchLabels:
app: keepalived-cloud-provider
strategy:
type: RollingUpdate
template:
metadata:
annotations:
scheduler.alpha.kubernetes.io/critical-pod: ""
scheduler.alpha.kubernetes.io/tolerations: '[{"key":"CriticalAddonsOnly", "operator":"Exists"}]'
labels:
app: keepalived-cloud-provider
spec:
containers:
- name: keepalived-cloud-provider
image: quay.io/munnerz/keepalived-cloud-provider:0.0.1
imagePullPolicy: IfNotPresent
env:
- name: KEEPALIVED_NAMESPACE
value: kube-system
- name: KEEPALIVED_CONFIG_MAP
value: vip-configmap
- name: KEEPALIVED_SERVICE_CIDR
value: 10.10.0.0/26 # pick a CIDR that is explicitly reservedfor keepalived
volumeMounts:
- name: certs
mountPath: /etc/ssl/certs
resources:
requests:
cpu: 200m
livenessProbe:
httpGet:
path: /healthz
port: 10252
host: 127.0.0.1
initialDelaySeconds: 15
timeoutSeconds: 15
failureThreshold: 8
volumes:
- name: certs
hostPath:
path: /etc/ssl/certs
Console
Copy
master $ kubectl apply -f cloudprovider.yaml
daemonset.extensions/kube-keepalived-vip created
configmap/vip-configmap created
deployment.apps/keepalived-cloud-provider created
Console
Copy
master $ kubectl get pods -n kube-system
NAME READY STATUS RESTARTS AGE
coredns-78fcdf6894-d4cwq 1/1 Running 0 11m
coredns-78fcdf6894-j2wc5 1/1 Running 0 11m
etcd-master 1/1 Running 0 10m
keepalived-cloud-provider-fb7465d76-jxckr 1/1 Running 0 9s
kube-apiserver-master 1/1 Running 0 10m
kube-controller-manager-master 1/1 Running 0 9m
kube-keepalived-vip-2rdt2 1/1 Running 0 9s
kube-proxy-rpmm5 1/1 Running 0 11m
kube-scheduler-master 1/1 Running 0 10m
weave-net-6ppzr 2/2 Running 1 11m
Console
Copy
master $ cat loadbalancer.yaml
yaml
Copy
apiVersion: v1
kind: Service
metadata:
name: webapp1-loadbalancer-svc
labels:
app: webapp1-loadbalancer
spec:
type: LoadBalancer
ports:
- port: 80
selector:
app: webapp1-loadbalancer
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: webapp1-loadbalancer-deployment
spec:
replicas: 2
template:
metadata:
labels:
app: webapp1-loadbalancer
spec:
containers:
- name: webapp1-loadbalancer-pod
image: katacoda/docker-http-server:latest
ports:
- containerPort: 80
---
Console
Copy
master $ kubectl apply -f loadbalancer.yaml
service/webapp1-loadbalancer-svc created
deployment.extensions/webapp1-loadbalancer-deployment created
Console
Copy
master $ kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 12m
webapp1-clusterip-svc ClusterIP 10.98.44.183 <none> 80/TCP 11m
webapp1-clusterip-targetport-svc ClusterIP 10.105.237.185 <none> 8080/TCP 8m
webapp1-externalip-svc ClusterIP 10.109.41.233 172.17.0.19 80/TCP 2m
webapp1-loadbalancer-svc LoadBalancer 10.110.83.174 10.10.0.1 80:31235/TCP 8s
webapp1-nodeport-svc NodePort 10.97.69.120 <none> 80:30080/TCP 5m
Console
Copy
master $ kubectl describe svc/webapp1-loadbalancer-svc
Name: webapp1-loadbalancer-svc
Namespace: default
Labels: app=webapp1-loadbalancer
Annotations: kubectl.kubernetes.io/last-applied-configuration={"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"labels":{"app":"webapp1-loadbalancer"},"name":"webapp1-loadbalancer-svc","namespace":...
Selector: app=webapp1-loadbalancer
Type: LoadBalancer
IP: 10.110.83.174
LoadBalancer Ingress: 10.10.0.1
Port: <unset> 80/TCP
TargetPort: 80/TCP
NodePort: <unset> 31235/TCP
Endpoints: 10.32.0.13:80,10.32.0.14:80
Session Affinity: None
External Traffic Policy: Cluster
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal CreatingLoadBalancer 19s service-controller Creating loadbalancer
Normal CreatedLoadBalancer 19s service-controller Created load balancer
Console
Copy
master $ export LoadBalancerIP=$(kubectl get services/webapp1-loadbalancer-svc -o go-template='{{(index .status.loadBalancer.ingress 0).ip}}')
master $ echo LoadBalancerIP=$LoadBalancerIP
LoadBalancerIP=10.10.0.1
Console
Copy
master $ curl $LoadBalancerIP
<h1>This request was processed by host: webapp1-loadbalancer-deployment-69b9f76fd6-zwgvz</h1>
Console
Copy
master $ curl $LoadBalancerIP
<h1>This request was processed by host: webapp1-loadbalancer-deployment-69b9f76fd6-wr847</h1>
Console
Copy
master $ curl $LoadBalancerIP
<h1>This request was processed by host: webapp1-loadbalancer-deployment-69b9f76fd6-zwgvz</h1>
편집자 Jmnote
로그인하시면 댓글을 쓸 수 있습니다.