실습
ClusterIP
cat <<'EOF' | kubectl apply -f - apiVersion: apps/v1 kind: Deployment metadata: name: nginx spec: replicas: 3 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx ports: - containerPort: 80 volumeMounts: - name: html mountPath: /usr/share/nginx/html initContainers: - name: index image: curlimages/curl command: - "sh" - "-c" - "echo 'hello from $(POD_NAME), my ip is $(POD_IP)' > /data/index.html" volumeMounts: - name: html mountPath: /data env: - name: POD_NAME valueFrom: fieldRef: fieldPath: metadata.name - name: POD_IP valueFrom: fieldRef: fieldPath: status.podIP volumes: - name: html emptyDir: {} EOFkubectl expose deployment nginx --port 80kubectl get svc nginx -o widekubectl get ep nginxkubectl get pod -l app=nginx -o widekubectl get ep nginx \ -o jsonpath='{range .subsets[*].addresses[*]}{.targetRef.name}{"\t"}{.ip}{"\n"}{end}'kubectl scale deployment nginx --replicas=6kubectl get pod -l app=nginx -o widekubectl get ep nginx \ -o jsonpath='{range .subsets[*].addresses[*]}{.targetRef.name}{"\t"}{.ip}{"\n"}{end}'kubectl run curl --image=nginx -- sleep 3600kubectl exec curl -- \ bash -c "for i in {1..20};do curl -s $(kubectl get svc nginx -o=jsonpath='{.spec.clusterIP}');done"kubectl -n kube-system logs ds/kube-proxy -fkubectl scale deployment nginx --replicas=3aws ssm start-session --target \ $(kubectl get node -o jsonpath='{.items[0].spec.providerID}{"\n"}' | grep -oE "i-[a-z0-9]+")sudo iptables-savesudo iptables -L -t natsudo iptables -t nat -L KUBE-SERVICES -n | column -texport SERVICE_CHAIN=$(sudo iptables -t nat -L KUBE-SERVICES -n | column -t | grep "default/nginx" | grep -oE "^KUBE-SVC-[A-Z0-9]+") echo $SERVICE_CHAINsudo iptables -t nat -L $SERVICE_CHAIN -n | column -tsudo iptables -t nat -L $(sudo iptables -t nat -L $SERVICE_CHAIN -n | column -t | grep -oE "^KUBE-SEP-[A-Z0-9]+" | head -1) \ -n | column -tkubectl get pod -o wide -l app=nginxkubectl scale deployment nginx --replicas=6kubectl -n kube-system get cm coredns -o yaml | yq e '.data' -cat <<EOF | kubectl apply -f - apiVersion: v1 kind: ConfigMap metadata: name: coredns namespace: kube-system labels: eks.amazonaws.com/component: coredns k8s-app: kube-dns data: Corefile: | .:53 { errors health kubernetes cluster.local in-addr.arpa ip6.arpa { pods insecure fallthrough in-addr.arpa ip6.arpa } prometheus :9153 forward . /etc/resolv.conf cache 30 loop reload loadbalance log } EOF{ kubectl -n kube-system scale deployment coredns --replicas=0 sleep 60 kubectl -n kube-system scale deployment coredns --replicas=2 sleep 10 kubectl -n kube-system get pod -l k8s-app=kube-dns }kubectl -n kube-system logs deploy/coredns -fkubectl exec curl -- cat /etc/resolv.confkubectl -n kube-system get svc kube-dnskubectl exec curl -- curl -s nginxkubectl create ns webkubectl -n web create deployment httpd --image=httpd --port=80kubectl -n web expose deployment httpdkubectl exec curl -- curl -s httpdkubectl exec curl -- curl -s httpd.webkubectl exec curl -- curl -s httpd.web.svckubectl exec curl -- curl -s httpd.web.svc.clusterkubectl exec curl -- curl -s httpd.web.svc.cluster.local{ kubectl delete ns web kubectl delete pod curl kubectl delete svc nginx kubectl delete deploy nginx }
NodePort
LoadBalancer
Network Load Balancer
Kubectl Proxy & Port-forwarding
ExternalName
Last updated