It looks like you can’t, if you don’t want to write your own YAML file. But that “container port” is useless as-is. The only usecase I can found (other than human awareness) is when you give a name to such a port :
---
apiVersion: apps/v1
kind: Deployment
spec:
template:
spec:
containers:
ports:
- name: myapp-http
containerPort: 8080
[...]
Then, instead of specifying a numbered port when creating a service
, you can refer to the named port. But that’s out-of-scope of what the kubectl create deployement ...
and kubectl expose ...
can do.
Just don’t add the ports definition in your container specs, if you can cope with it.
Reference:
$ kubectl explain pod.spec.containers.ports