Replacing a Specified NetworkPolicy

Function

This API is used to replace a specified NetworkPolicy.

URL

PUT /apis/networking.k8s.io/v1/namespaces/{namespace}/networkpolicies/{name}

The following fields can be updated:

  • metadata.name
  • metadata.namespace
  • metadata.selfLink
  • metadata.resourceVersion
  • metadata.uid
  • metadata.labels
  • metadata.annotations
  • spec.ingress

Table 1 describes the parameters of the API.

Table 1 Parameter description

Parameter

Mandatory

Description

name

Yes

Name of the NetworkPolicy.

namespace

Yes

Object name and auth scope, such as for teams and projects.

pretty

No

If 'true', then the output is pretty printed.

body

Yes

-

Request

Request parameters:

For the description about request parameters, see Table 2.

For the description about the Content-Type field, see Patch Request Method Operation Description.

Example request:

{
    "kind": "NetworkPolicy",
    "apiVersion": "networking.k8s.io/v1",
    "metadata": {
	    "name": "test-network-policy",
		"namespace": "default",
		"resourceVersion": "213982",
		"generation": 1,
            "labels": {
		"app": "nginx"
			}
	},
    "spec": {
	    "podSelector": {
		"matchLabels": {
		    "app": "nginx"
		    }
	    },
	    "ingress": [{
		"from": [{
		    "podSelector": {
		        "matchLabels": {
			    "app": "nginx3"
				    }
			    }
		}],
	    "ports": [{
	        "protocol": "TCP",
		"port": 6379
		}]
	    }],
	    "policyTypes":[
		"Ingress"
        ]
    }
}

Response

Response parameters:

For the description about response parameters, see Table 2.

Example response:

{
    "kind": "NetworkPolicy",
    "apiVersion": "networking.k8s.io/v1",
    "metadata": {
	    "name": "test-network-policy",
		"namespace": "default",
		"selfLink": "/apis/networking.k8s.io/v1/namespaces/default/networkpolicies/test-network-policy",
		"uid": "be347ddd-e8af-11e8-b187-fa163e3cca63",
		"resourceVersion": "213982",
		"generation": 1,
		"creationTimestamp": "2018-11-15T08:23:34Z",
            "labels": {
		"app": "nginx",
			}
	}
    "spec": {
	    "podSelector": {
		"matchLabels": {
		    "app": "nginx"
		    }
	    },
	    "ingress": [{
		"from": [{
		    "podSelector": {
		        "matchLabels": {
			    "app": "nginx3"
				    }
			    }
		}],
	    "ports": [{
	        "protocol": "TCP",
		"port": 6379
		}]
	    }],
	    "policyTypes":{ 
		"Ingress"
        }
    }
}

Status Code

Table 2 describes the status codes of this API.

Table 2 Status codes

Status Code

Description

200

OK

201

Created