Introduction#
- question 15 network policy
- question 16 expose service
- question 17 ingress rules
Question 15 Network Policy#
- create a namespace app-stack
- retrieve the pod definition https://github.com/speedracer55/ckad-files/blob/main/networkp.yaml
- create a network policy
- the network policy should allow incoming traffic from the backend to the database
- disallow the incoming traffic from the frontend to the database
- incoming traffic to the database should only allowed on TCP port 3306
please install Callio network policy engine for AWS EKS first
create a namespace app-stack
kubectl create namespace app-stack
deploy three pods
kubectl create -f q15.yaml
create a network policy yaml, follow this link
apiVersion: networking.k8s.io/v1kind: NetworkPolicymetadata:name: app-stack-network-policynamespace: app-stackspec:podSelector:matchLabels:app: todotier: databasepolicyTypes:- Ingress- Egressingress:- from:- podSelector:matchLabels:app: todotier: backendports:- protocol: TCPport: 3306
verify that allow backend => connect db:3306
kubectl run busybox --image=busybox --labels="app=todo,tier=backend" -it --rm -- /bin/sh --namespace=app-stack
then get the backend ip address
kubectl get pods --namespace=app-stack --output=wide
wget -O- BACKEND_IP_ADDRESS
verify that deny frontend => connect db:3306
kubectl run busybox --image=busybox --labels="app=todo,tier=frontend" -it --rm -- /bin/sh --namespace=app-stack
Question 16 Expose Service#
- create a service named myapp of type clusterIP that exposes port 80 to target port 80
- create a deployment named myapp that create 1 replica running the image nginx
- expose the container on port 80
- verify that port 80 is exposed - list the endpoint values
- scale the deployment to 2 replicas
- create a temporary pod using busybox and run wget command against the IP address of the service
- change the service type so the pods can be reached from outside of the cluster
- run wget command against the service from outside the cluster
create a service named myapp
kubectl create service myapp clusterip --tcp=80:80 --dry-run=client --output=yaml > q14_service.yaml
content of the service yaml
apiVersion: v1kind: Servicemetadata:creationTimestamp: nulllabels:app: myappname: myappspec:ports:- name: 80-80port: 80protocol: TCPtargetPort: 80selector:app: myapptype: ClusterIPstatus:loadBalancer: {}
create deployment named myapp with 1 replica and image nginx, port 80
kubectl create deployment myapp --image=nginx --replica=1 --port=80 --dry-run=client --output=yaml > q14_deployment.yaml
deploy the service and deployment
kubectl create -f q14_service.yamlkubectl create -f q14_deployment.yaml
expose the service on port 8
kubectl expose service myapp --port=80
verify that service and endpoint
kubectl get service myappkubectl describe service myappkubectl get pods --output=wide
scale the deployment to 2 replicas
kubectl scale --replicas=2 deployment myapp
create a temporary busybox and wget to the service
kubectl run busybox --image=busybox --rm -it -- /bin/sh
then wget -O- to the ip address of the service
wget -O- SERVICE_IP_ADDRESS
change expose type to loadBalancer in AWS so it can be access from outside of the cluster
kubectl edit service myapp
edit the service yaml
apiVersion: v1kind: Servicemetadata:creationTimestamp: nulllabels:app: myappname: myappspec:ports:- name: 80-80port: 80protocol: TCPtargetPort: 80selector:app: myapptype: LoadBalancerstatus:loadBalancer: {}
verify that the service can be accessed from outside of the cluster
kubectl get service myappwget -O- SERVICE_IP_ADDRESS