Exercise 9.1: Deploy a New Service
cat <<EOF | kubectl apply -f - apiVersion: apps/v1 kind: Deployment metadata: name: nginx-one labels: system: secondary namespace: accounting spec: selector: matchLabels: system: secondary replicas: 2 template: metadata: labels: system: secondary spec: containers: - image: nginx:1.20.1 imagePullPolicy: Always name: nginx ports: - containerPort: 8080 protocol: TCP nodeSelector: system: secondOne EOFkubectl create ns accountingcat <<EOF | kubectl apply -f - apiVersion: apps/v1 kind: Deployment metadata: name: nginx-one labels: system: secondary namespace: accounting spec: selector: matchLabels: system: secondary replicas: 2 template: metadata: labels: system: secondary spec: containers: - image: nginx:1.20.1 imagePullPolicy: Always name: nginx ports: - containerPort: 8080 protocol: TCP nodeSelector: system: secondOne EOFkubectl get pod -n accountingkubectl describe pod POD_NAME -n accountingkubectl describe pod $(kubectl get pod -l system=secondary -o=jsonpath='{.items[0].metadata.name}' -n accounting) -n accountingkubectl get node --show-labelskubectl label node worker system=secondOnekubectl get node --show-labelskubectl get pod -n accountingkubectl expose deployment/nginx-one -n accountingkubectl get ep nginx-one -n accountingcurl ENDPOINT_IP:ENDPOINT_PORTcurl $(kubectl get ep nginx-one -o=jsonpath='{.subsets[0].addresses[0].ip}:{.subsets[0].ports[0].port}' -n accounting)curl ENDPOINT_IP:80curl $(kubectl get ep nginx-one -o=jsonpath='{.subsets[0].addresses[0].ip}:80' -n accounting)cat <<EOF | kubectl apply -f - apiVersion: apps/v1 kind: Deployment metadata: name: nginx-one labels: system: secondary namespace: accounting spec: selector: matchLabels: system: secondary replicas: 2 template: metadata: labels: system: secondary spec: containers: - image: nginx:1.20.1 imagePullPolicy: Always name: nginx ports: - containerPort: 80 protocol: TCP nodeSelector: system: secondOne EOFcurl $(kubectl -n accounting get svc nginx-one -o=jsonpath='{.spec.clusterIP}')kubectl -n accounting get svc nginx-onekubectl -n accounting patch svc nginx-one --type=json -p='[ {"op": "replace", "path": "/spec/ports/0/port", "value": 80}, {"op": "replace", "path": "/spec/ports/0/targetPort", "value": 80}]'kubectl -n accounting get svc nginx-onecurl $(kubectl -n accounting get svc nginx-one -o=jsonpath='{.spec.clusterIP}')sudo iptables-savesudo iptables -L -t natsudo iptables -t nat -L KUBE-SERVICES -n | column -tkubectl -n accounting get svc nginx-one{ export SERVICE_CHAIN=$(sudo iptables -t nat -L KUBE-SERVICES -n | column -t | grep "accounting/nginx-one" | grep -oE "^KUBE-SVC-[A-Z0-9]+") sudo iptables -t nat -L $SERVICE_CHAIN -n | column -t }sudo 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 -n accounting get pod -l system=secondary -o widekubectl -n accounting scale deployment nginx-one --replicas=6sudo iptables -t nat -L $SERVICE_CHAIN -n | column -tkubectl -n kube-system logs ds/kube-proxykubectl -n kube-system patch ds kube-proxy --type=json \ -p='[{"op": "add", "path": "/spec/template/spec/containers/0/command/-", "value": "--v=10"}]'kubectl -n kube-system get pod -l k8s-app=kube-proxykubectl -n accounting scale deployment nginx-one --replicas=2sudo iptables -t nat -L $SERVICE_CHAIN -n | column -tkubectl -n kube-system logs ds/kube-proxy
Last updated