{"id":5,"date":"2022-03-18T21:46:43","date_gmt":"2022-03-18T21:46:43","guid":{"rendered":"https:\/\/aminshateri.com\/?post_type=article&#038;p=5"},"modified":"2022-03-18T21:49:55","modified_gmt":"2022-03-18T21:49:55","slug":"cka-certified-kubernetes-administrator-2022","status":"publish","type":"article","link":"https:\/\/aminshateri.com\/index.php\/articles\/cka-certified-kubernetes-administrator-2022\/","title":{"rendered":"CKA-Certified-Kubernetes-Administrator-2022"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">I have recently taken the CKA exam and I am interested in preparing you for the exam by sharing sample questions that you may face in the exam.<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p class=\"wp-block-paragraph\"><em>5. Create a new&nbsp;<strong>NetworkPolicy<\/strong>&nbsp;name&nbsp;<strong>allow-port-from-namespace<\/strong>&nbsp;that allows Pods in the existing namespace&nbsp;<strong>echo<\/strong>&nbsp;to connect to port&nbsp;<strong>9000<\/strong>&nbsp;of other Pods in the same namespace, Ensure that the new NetworkPolicy:<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>* does not allow access to Pods not listening on port 9000<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>* does not allow access from Pods not in namespace internal<\/em><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Answer<\/h4>\n\n\n\n<ul class=\"wp-block-list\"><li>First, you should search &#8220;NetworkPolicy&#8221; in the kubernetes.io document and then copy the first NetworkPolicy YAML file and then delete unused lines, finally, the below YAML file will remain:<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\"># vim networkpol.yaml\r\n\r\n<\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>apiVersion: networking.k8s.io\/v1\r\nkind: NetworkPolicy\r\nmetadata:\r\n  name: all-port-from-namespace        #This line is changed\r\n  namespace: echo        #This line should be changed\r\nspec:\r\n  podSelector:\r\n    matchLabels: {}\r\n  ingress:\r\n  - from:\r\n    - namespaceSelector:\r\n        matchLabels:\r\n          name: internal        #This line is changed \r\n    - podSelector: {}\r\n    ports:\r\n    - port: 9000        #This line is changed<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>Then you should create network policy with<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\"><code># kubectl create -f networkpol.yaml<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have recently taken the CKA exam and I am interested in preparing you for the exam by sharing sample questions that you may face in the exam.<\/p>\n","protected":false},"featured_media":0,"template":"","class_list":["post-5","article","type-article","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/aminshateri.com\/index.php\/wp-json\/wp\/v2\/article\/5","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/aminshateri.com\/index.php\/wp-json\/wp\/v2\/article"}],"about":[{"href":"https:\/\/aminshateri.com\/index.php\/wp-json\/wp\/v2\/types\/article"}],"wp:attachment":[{"href":"https:\/\/aminshateri.com\/index.php\/wp-json\/wp\/v2\/media?parent=5"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}