-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
87 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
--- | ||
title: "NetworkPolicy " | ||
description: "networking" | ||
weight: 15 | ||
--- | ||
|
||
It looks like you want to apply a Kubernetes NetworkPolicy that you've defined in a file using `kubectl`, the command-line tool for interacting with Kubernetes. If you're asking about how to handle file input operations including the end-of-file (EOF) marker for creating or editing files directly in the command line, I can guide you through creating or appending to a file using terminal commands. | ||
|
||
### Creating a File with EOF Marker | ||
To create a new file or overwrite an existing file with your NetworkPolicy content directly from the terminal, you can use the following method: | ||
|
||
```bash | ||
cat <<EOF > networkpolicy.yaml | ||
kind: NetworkPolicy | ||
apiVersion: networking.k8s.io/v1 | ||
metadata: | ||
name: access-nginx # pick a name | ||
spec: | ||
podSelector: | ||
matchLabels: | ||
app: nginx # selector for the pods | ||
ingress: # allow ingress traffic | ||
- from: | ||
- podSelector: # from pods | ||
matchLabels: # with this label | ||
access: granted | ||
EOF | ||
``` | ||
|
||
This command will start `cat` in "here document" mode, which allows input until the end-of-file marker `EOF` is reached. The content between the initial `cat <<EOF > networkpolicy.yaml` and the final `EOF` is written into the `networkpolicy.yaml` file. | ||
|
||
### Applying the NetworkPolicy | ||
Once you have the file ready (`networkpolicy.yaml`), you can apply it to your Kubernetes cluster with this command: | ||
|
||
```bash | ||
kubectl apply -f networkpolicy.yaml | ||
``` | ||
|
||
This command tells `kubectl` to apply the configurations defined in `networkpolicy.yaml` to your Kubernetes cluster. | ||
|
||
### Checking the Application of the NetworkPolicy | ||
After applying the NetworkPolicy, you can confirm it's been applied correctly by listing all network policies in the `default` namespace: | ||
|
||
```bash | ||
kubectl get networkpolicy -n default | ||
``` | ||
|
||
This will display all network policies that have been configured in the `default` namespace, including your new `internal-policy`. | ||
|
||
These steps will help you create, apply, and verify the application of your Kubernetes NetworkPolicy directly from the command line. If you have any more questions or need further assistance with Kubernetes, feel free to ask! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--- | ||
title: "Use Core DNS" | ||
description: "networking" | ||
weight: 16 | ||
--- | ||
|
||
|
||
sangam@sangam:~$ kubectl create service clusterip my-service --tcp=8080:8080 | ||
service/my-service created | ||
sangam@sangam:~$ kubectl get service | ||
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE | ||
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 45h | ||
my-service ClusterIP 10.106.213.25 <none> 8080/TCP 5s | ||
sangam@sangam:~$ kubectl run busybox --image=busybox -it -- /bin/sh | ||
If you don't see a command prompt, try pressing enter. | ||
/ # | ||
/ # | ||
/ # nslookup 10.106.213.25 | ||
Server: 10.96.0.10 | ||
Address: 10.96.0.10:53 | ||
|
||
25.213.106.10.in-addr.arpa name = my-service.default.svc.cluster.local | ||
|
||
/ # exit | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+46.9 KB
...-base-2_hu06b1a92291a380a0d2e0ec03dab66b2f_17642_filter_5046882770084248480.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+46.7 KB
...-base-2_hu06b1a92291a380a0d2e0ec03dab66b2f_17642_filter_7293408560870142390.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.