Google course on Kubernetes proposes:
$ kubectl run kubernetes-bootcamp --image=gcr.io/google-samples/kubernetes-bootcamp:v1 --port=8080
kubectl run --generator=deployment/apps.v1 is DEPRECATED and will be removed in a future version.
Use kubectl run --generator=run-pod/v1 or kubectl create instead.Now I'm trying to use the new syntax:
$ kubectl create deployment kubernetes-bootcamp --image=gcr.io/google-samples/kubernetes-bootcamp:v1
$ kubectl expose deployment/kubernetes-bootcamp --port=8080 type=NodePortI'm sure that they are not the same. Could anyone help me?
Rr
Not duplicate: I'm asking about equivalence of two commands
You can see what these commands do by executing a dry-run and inspecting the generated manifests:
kubectl run kubernetes-bootcamp --image=gcr.io/google-samples/kubernetes-bootcamp:v1 --port=8080 \
--dry-run -o yaml > kubectl-run.yamlAnd
kubectl create deployment kubernetes-bootcamp --image=gcr.io/google-samples/kubernetes-bootcamp:v1 \
--dry-run -o yaml >kubectl-create.yamlThe only substantial difference between the two manifests is that there is no ports field in kubectl-create.yaml.
The kubectl create deployment command has no option for specifying any exposed ports of the container, so there's probably no easy way to achieve exactly the same output as kubectl run with a kubectl create command.
The kubectl expose command that you're using just creates a Service resource and doesn't modify the Deployment resource.
In general, kubectl create <resource> commands are rather limited. They're mostly useful to either create a resource with only default settings, or to create the base for a manifest with --dry-run -o yaml that you can then customise.
Deployments has no --port option as you are guessing correctly. It is the port the container listen to, which makes the difference.
The service you use to expose the deployment should say which container port should be exposed - and to which port of the service it should map the container port to.
$ kubectl expose deployment/kubernetes-bootcamp --port=80 --container-port=8080 type=NodePortThe above command exposes the bootcamp via port 80.